Пример #1
0
def hlpr(image):
    image = data.hubble_deep_field()[0:500, 0:500]
    image_gray = rgb2gray(image)

    blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

    blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
    blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

    blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ['yellow', 'lime', 'red']
    titles = [
        'Laplacian of Gaussian', 'Difference of Gaussian',
        'Determinant of Hessian'
    ]
    sequence = zip(blobs_list, colors, titles)

    for blobs, color, title in sequence:
        fig, ax = plt.subplots(1, 1)
        ax.set_title(title)
        ax.imshow(image, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
            ax.add_patch(c)

    plt.show()
Пример #2
0
def hlpr(image):
 image = data.hubble_deep_field()[0:500, 0:500]
 image_gray = rgb2gray(image)

 blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
 # Compute radii in the 3rd column.
 blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

 blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
 blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

 blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

 blobs_list = [blobs_log, blobs_dog, blobs_doh]
 colors = ['yellow', 'lime', 'red']
 titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']
 sequence = zip(blobs_list, colors, titles)

 for blobs, color, title in sequence:
    fig, ax = plt.subplots(1, 1)
    ax.set_title(title)
    ax.imshow(image, interpolation='nearest')
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
        ax.add_patch(c)

 plt.show()
Пример #3
0
def test_blob_detection():

    viewer = napari.Viewer()
    viewer.window.add_dock_widget(blob_detection())

    image = data.hubble_deep_field()[0:500, 0:500]
    image_gray = rgb2gray(image)

    viewer.add_image(image_gray)
Пример #4
0
 def setUp(self):
     self.descriptor = HogDescriptor(block_size=(16, 16),
                                     cell_size=(8, 8),
                                     orientations=9)
     self.images = [
         data.astronaut(),
         data.hubble_deep_field(),
         data.coffee()
     ]
     self.images = [cv2.resize(im, (256, 256)) for im in self.images]
Пример #5
0
def print_image_info_test():
    img=data.hubble_deep_field()
    print(type(img))  # 显示类型 
    print(img.shape)  # 显示尺寸 
    print(img.shape[0])  # 图片宽度 
    print(img.shape[1])  # 图片高度 
    print(img.shape[2])  # 图片通道数 
    print(img.size)   # 显示总像素数 
    print(img.max())  # 最大像素值 
    print(img.min())  # 最小像素值 
    print(img.mean()) # 平均像素值
Пример #6
0
def process_selection(img_selected):
    if img_selected == "ASTRONAUT":
        return data.astronaut()
    if img_selected == "CHECKER":
        return data.checkerboard()
    if img_selected == "COINS":
        return data.coins()
    if img_selected == "HUBBLE":
        return data.hubble_deep_field()
    if img_selected == "HORSE":
        return data.horse()
    if img_selected == "CAMERA":
        return data.camera()
    if img_selected == "COFFEE":
        return data.coffee()
    else:
        return data.astronaut()
Пример #7
0
import matplotlib.pyplot as plt
from skimage import data

from skimage import io

import nibabel

from urllib import urlretrieve
import zipfile

import tempfile
import os

astronaut = data.astronaut()
ihc = data.immunohistochemistry()
hubble = data.hubble_deep_field()

# create a temporary directory
d = tempfile.mkdtemp()

# os.path.basename(u'https://www.google.com/attention.zip')

# initialize the subplot panels side by side
fig, ax = plt.subplots(nrows=1, ncols=3)

# show an image in each subplot
ax[0].imshow(astronaut)
ax[0].set_title(u'Natural image')
ax[1].imshow(ihc)
ax[1].set_title(u'Microscope image')
ax[2].imshow(hubble)
Пример #8
0
# -*- coding: utf-8 -*-
"""
学习 skimage blob detection
"""

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray

image = data.hubble_deep_field()[0:500, 0:500]
image_gray = rgb2gray(image)

plt.imshow(image)
plt.show()

blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = [
    'Laplacian of Gaussian', 'Difference of Gaussian', 'Determinant of Hessian'
]
Пример #9
0
) -> Future[LayerDataTuple]:

    # long running function
    def _make_blob():
        # skimage.feature may take a while depending on the parameters
        blobs = blob_log(
            image,
            min_sigma=min_sigma,
            max_sigma=max_sigma,
            num_sigma=num_sigma,
            threshold=threshold,
        )
        data = blobs[:, :image.ndim]
        kwargs = dict(
            size=blobs[:, -1],
            edge_color="red",
            edge_width=2,
            face_color="transparent",
        )
        return (data, kwargs, 'points')

    return pool.submit(_make_blob)


viewer = napari.Viewer()
viewer.window.add_dock_widget(make_widget(), area="right")
viewer.add_image(data.hubble_deep_field().mean(-1))

napari.run()
pool.shutdown(wait=True)
Пример #10
0
#####################################################################
# Comparing Different Classes of Denoiser
# =========================================
# The self-supervised loss can be used to compare different classes of
# denoiser in addition to choosing parameters for a single class.
# This allows the user to, in an unbiased way, choose the best parameters
# for the best class of denoiser for a given image.
#
# Below, we show this for an image of the hubble deep field with significant
# speckle noise added. In this case, the J-invariant calibrated denoiser is
# better than the default denoiser in each of three families of denoisers --
# Non-local means, wavelet, and TV norm. Additionally, the self-supervised
# loss shows that the TV norm denoiser is the best for this noisy image.
#

image = rgb2gray(img_as_float(hubble_deep_field()[100:250, 50:300]))

sigma = 0.4
noisy = random_noise(image, mode='speckle', var=sigma**2)

parameter_ranges_tv = {'weight': np.arange(0.01, 0.3, 0.02)}
_, (parameters_tested_tv,
    losses_tv) = calibrate_denoiser(noisy,
                                    denoise_tv_chambolle,
                                    denoise_parameters=parameter_ranges_tv,
                                    extra_output=True)
print(f'Minimum self-supervised loss TV: {np.min(losses_tv):.4f}')

best_parameters_tv = parameters_tested_tv[np.argmin(losses_tv)]
denoised_calibrated_tv = _invariant_denoise(noisy,
                                            denoise_tv_chambolle,
from skimage.color import rgb2gray, gray2rgb
from skimage.segmentation import mark_boundaries
import time
import matplotlib.image as mpimg
exec(open('/Users/Salim_Andre/Desktop/IMA/PRAT/code/pd_segmentation_0.py').read())
exec(open('/Users/Salim_Andre/Desktop/IMA/PRAT/code/tree.py').read())

### DATASET

PATH_img = '/Users/Salim_Andre/Desktop/IMA/PRAT/' # path to my own images

swans=mpimg.imread(PATH_img+'swans.jpg');
baby=mpimg.imread(PATH_img+'baby.jpg'); 
	
img_set = [data.astronaut(), data.camera(), data.coins(), data.checkerboard(), data.chelsea(), \
	data.coffee(), data.clock(), data.hubble_deep_field(), data.horse(), data.immunohistochemistry(), \
	data.moon(), data.page(), data.rocket(), swans, baby]
	
### IMAGE

I=img_as_float(img_set[0]);

###	PARAMETERS FOR 0-HOMOLOGY GROUPS

mode='customized';
n_superpixels=10000;
RV_epsilon=30;
gauss_sigma=0.5;
list_events=[800];
n_pxl_min_ = 30;
density_excl=0.0;
Пример #12
0
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 16:53:38 2015

@author: prassanna
"""

from skimage import io, color,data,segmentation
import numpy as np

img = data.hubble_deep_field();
img_gray = color.rgb2gray(img)
#io.imshow(img)

segment_map= segmentation.slic(img,compactness=10);
img_contours = segmentation.mark_boundaries(img_gray,segment_map)
io.imshow(img_contours)


def calc_statistics(img,segments):
    sup_brightness = [np.mean(img[segments==i]) for i in range(0,np.amax(segments)+1)]
    return sup_brightness
        
def look_at_brightest(superpixel_intensities, nr_select=3):
    thresh = sorted(superpixel_intensities)[-1*nr_select]
    return thresh
    

    
sup_intensities = calc_statistics(img_gray,segment_map);
sup_thresh = look_at_brightest(sup_intensities)    
Пример #13
0
# https://scikit-image.org/docs/stable/auto_examples/features_detection/plot_blob.html

from matplotlib import pyplot as plt
from scipy import ndimage as ndi
import numpy as np
from skimage import data
from math import sqrt
from skimage.feature import blob_log, peak_local_max
from skimage.color import rgb2gray
from skimage.measure import regionprops
from skimage.filters import gaussian, threshold_otsu
from skimage.segmentation import watershed
#############
# IMAGE
#############
img_stars = data.hubble_deep_field()[0:500, 0:500]
stars_gray = rgb2gray(img_stars)

#############
# BLOB DETECTION
#############
blobs_log = blob_log(stars_gray,
                     min_sigma=1,
                     max_sigma=30,
                     num_sigma=50,
                     threshold=.1)
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
numrows = len(blobs_log)
print("Number of blobs counted : ", numrows)
Пример #14
0
This example shows how to remove small objects from grayscale images.
The top-hat transform [1]_ is an operation that extracts small elements and
details from given images. Here we use a white top-hat transform, which is
defined as the difference between the input image and its
(mathematical morphology) opening.

.. [1] https://en.wikipedia.org/wiki/Top-hat_transform

"""

import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage import color, morphology

image = color.rgb2gray(data.hubble_deep_field())[:500, :500]

footprint = morphology.disk(1)
res = morphology.white_tophat(image, footprint)

fig, ax = plt.subplots(ncols=3, figsize=(20, 8))
ax[0].set_title('Original')
ax[0].imshow(image, cmap='gray')
ax[1].set_title('White tophat')
ax[1].imshow(res, cmap='gray')
ax[2].set_title('Complementary')
ax[2].imshow(image - res, cmap='gray')

plt.show()
Пример #15
0
This is the fastest approach. It detects blobs by finding maximas in the
matrix of the Determinant of Hessian of the image. The detection speed is
independent of the size of blobs as internally the implementation uses
box filters instead of convolutions. Bright on dark as well as dark on
bright blobs are detected. The downside is that small blobs (<3px) are not
detected accurately. See :py:meth:`skimage.feature.blob_doh` for usage.

"""

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray

image = data.hubble_deep_field()[0:500, 0:500]
image_gray = rgb2gray(image)

blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']
Пример #16
0
print img.shape
io.imshow(img)

##Gaussian
noisy = img + 0.6 * img.std() * np.random.random(img.shape)
noisy = np.clip(noisy, 0, 1)
blurred = filter.gaussian_filter(noisy, 2);
#blurred_int = np.uint8(blurred*255)
#print np.amax(blurred_int)
bla = np.vstack((img,noisy,blurred))
io.imshow(bla)


#2nd Gaussian
from math import sqrt
img_2  = data.hubble_deep_field()
img_2  = img_2 [0:500,0:500]
io.imshow(img_2)
img_gray = color.rgb2gray(img_2)

blobs_log = feature.blob_log(img_gray, max_sigma=30, num_sigma=10, threshold=.1)
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = feature.blob_dog(img_gray, max_sigma=30, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)


def disp_blob(blobs,title):
    fig, ax = plt.subplots(1,1)
    ax.set_title(title)    
    ax.imshow(img_2, interpolation='nearest')
Пример #17
0
We detect local maxima in a galaxy image. The image is corrupted by noise,
generating many local maxima. To keep only those maxima with sufficient
local contrast, we use h-maxima.
"""
import numpy as np

import matplotlib.pyplot as plt

from skimage.measure import label
from skimage import data
from skimage import color
from skimage.morphology import extrema
from skimage import exposure


color_image = data.hubble_deep_field()

# for illustration purposes, we work on a crop of the image.
x_0 = 70
y_0 = 354
width = 100
height = 100

img = color.rgb2gray(color_image)[y_0:(y_0 + height), x_0:(x_0 + width)]

# the rescaling is done only for visualization purpose.
# the algorithms would work identically in an unscaled version of the
# image. However, the parameter h needs to be adapted to the scale.
img = exposure.rescale_intensity(img)

Пример #18
0
 def test_resize_images(self):
     images = [data.astronaut(), data.hubble_deep_field(), data.coffee()]
     images = resize_images(images, (256, 256))
     [self.assertEqual(im.shape, (256, 256, 3)) for im in images]
Пример #19
0
    plt.figure()
    plt.title(name)
    if image.ndim == 2:
        plt.imshow(image, cmap=plt.cm.gray)
    else:
        plt.imshow(image)

plt.show()

############################################################################
# Thumbnail image for the gallery

# sphinx_gallery_thumbnail_number = -1

fig, axs = plt.subplots(nrows=3, ncols=3)
for ax in axs.flat:
    ax.axis("off")
axs[0, 0].imshow(data.hubble_deep_field())
axs[0, 1].imshow(data.immunohistochemistry())
axs[0, 2].imshow(data.lily())
axs[1, 0].imshow(data.microaneurysms())
axs[1, 1].imshow(data.moon(), cmap=plt.cm.gray)
axs[1, 2].imshow(data.retina())
axs[2, 0].imshow(data.shepp_logan_phantom(), cmap=plt.cm.gray)
axs[2, 1].imshow(data.skin())
further_img = np.full((300, 300), 255)
for xpos in [100, 150, 200]:
    further_img[150 - 10:150 + 10, xpos - 10:xpos + 10] = 0
axs[2, 2].imshow(further_img, cmap=plt.cm.gray)
plt.subplots_adjust(wspace=-0.3, hspace=0.1)
We detect local maxima in a galaxy image. The image is corrupted by noise,
generating many local maxima. To keep only those maxima with sufficient
local contrast, we use h-maxima.
"""
import numpy as np

import matplotlib.pyplot as plt

from skimage.measure import label
from skimage import data
from skimage import color
from skimage.morphology import extrema
from skimage import exposure


color_image = data.hubble_deep_field()

# for illustration purposes, we work on a crop of the image.
x_0 = 70
y_0 = 354
width = 100
height = 100

img = color.rgb2gray(color_image)[y_0:(y_0 + height), x_0:(x_0 + width)]

# the rescaling is done only for visualization purpose.
# the algorithms would work identically in an unscaled version of the
# image. However, the parameter h needs to be adapted to the scale.
img = exposure.rescale_intensity(img)

Пример #21
0
from math import sqrt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from skimage.color import rgb2gray
from skimage.io import *

import numpy as np
import matplotlib.pyplot as plt

img1 = data.hubble_deep_field()[0:500, 0:500]
img1 = rgb2gray(img1)

#img1 = imread('sunflower.jpg')
#img1 = rgb2gray(img1)

img2 = imread('p2.jpg')
img2 = rgb2gray(img2)

img3 = imread('p3.jpg')
img3 = rgb2gray(img3)

blob_log = blob_log(img1, max_sigma=30, num_sigma=10, threshold=.2)
blob_log[:, 2] = blob_log[:, 2] * sqrt(2)

fig, axes = plt.subplots(1, 3, figsize=(9, 3), sharex=True, sharey=True)

ax = axes.ravel()

ax[0].set_title('LoG filter with puppy image')
ax[0].imshow(img1, interpolation='nearest')
Пример #22
0
  of the disk filter with a corresponding radius. In general however,
  the filter size parameter has to be examined when comparing the two.
- There is an inherent loss of information (resolution) in the
  holographic reconstruction process. The side band is isolated with a
  low-pass filter in Fourier space. The size and shape of this filter
  determine the resolution of the phase and amplitude images. As a
  result, the level of detail of all reconstructions shown is lower
  than that of the original images.
"""
import matplotlib.pylab as plt
import numpy as np
import qpimage
from skimage import color, data

# image of a galaxy recorded with the Hubble telescope
img1 = color.rgb2grey(data.hubble_deep_field())[354:504, 70:220]
# image of a coin
img2 = color.rgb2grey(data.coins())[150:300, 70:220]

pha = img1/img1.max() * 2 * np.pi
amp = img2/img2.mean()

# create a hologram
x, y = np.mgrid[0:150, 0:150]
hologram = 2 * amp * np.cos(-2 * (x + y) + pha)

filters = ["disk", "smooth disk", "gauss"]
qpis = []

for filter_name in filters:
    qpi = qpimage.QPImage(data=hologram,
Пример #23
0
#!/usr/bin/env python
import matplotlib.pyplot as plt
from skimage import data
from skimage.feature import blob_doh
from skimage.color import rgb2gray


if __name__ == '__main__':

    image = data.hubble_deep_field()[0:330, 200:500]
    image_gray = rgb2gray(image)

    blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

    fig, (ax0, ax1) = plt.subplots(nrows=1, ncols=2, figsize=(3.8, 2))
    ax0.imshow(image, interpolation='nearest')
    ax1.imshow(image, interpolation='nearest')
    for blob in blobs_doh:
        y, x, r = blob
        c = plt.Circle((x, y), r, color='red', linewidth=1.5, fill=False)
        ax1.add_patch(c)

    ax0.axis('off')
    ax1.axis('off')
    fig.subplots_adjust(0, 0, 1, 1, 0.075, 0)
    fig.savefig('./doh_galaxies.png', dpi=250)
Пример #24
0
def test_hubble():
    """ Test that "Hubble" image can be loaded. """
    data.hubble_deep_field()
# <codecell>

skdemo.imshow_all(image, morphology.closing(image, sq)) # dilation -> erosion   


# <markdowncell>
# **Exercise**: use morphological operations to remove noise from a binary
# image.



# <codecell>

from skimage import data, color
hub = color.rgb2gray(data.hubble_deep_field()[350:450, 90:190])
plt.imshow(hub);   


# <markdowncell>
# Remove the smaller objects to retrieve the large galaxy.


# <markdowncell>
# ---
# 
# <div style="height: 400px;"></div>



# <codecell>