def load_image(fname):
    """Load one of the samples images and show different color channels

    Args:
        fname: filename (or path) of the image. Will load a default image from
            skimage immunohistochemistry if empty.

    Returns:
        img: loaded image
    """
    if fname is not None:
        assert os.path.exists(fname), '{} not found'.format(fname)
        img = io.imread(fname)
    else:
        img = data.immunohistochemistry()
    return img
Beispiel #2
0
def demo_data():
    im = data.immunohistochemistry()
    l_c = 128
    l_r = 180
    n_rows = 1
    n_cols = im.shape[1] // l_c
    init_i, init_j = 0, 0
    overlap_h = [5, 25]

    big_im = np.empty((n_rows * l_r, n_cols * l_c, 3), dtype=im.dtype)
    i = 0
    for j in range(n_cols):
        sub_im = im[init_i:init_i + l_r, init_j:init_j + l_c]
        big_im[i * l_r:(i + 1) * l_r, j * l_c:(j + 1) * l_c] = sub_im
        init_j += l_c - overlap_h[1]
        init_i += overlap_h[0]
    return big_im
Beispiel #3
0
def intense(image, in_range='image', out_range='dtype'):
    
    cmap_hema = LinearSegmentedColormap.from_list('mycmap', ['white', 'navy'])
    cmap_dab = LinearSegmentedColormap.from_list('mycmap', ['white',
                                                 'saddlebrown'])
    cmap_eosin = LinearSegmentedColormap.from_list('mycmap', ['darkviolet',
                                                   'white'])
    
    ihc_rgb = data.immunohistochemistry()
    ihc_hed = rgb2hed(ihc_rgb)
    
    fig, axes = plt.subplots(2, 2, figsize=(7, 6), sharex=True, sharey=True)
    ax = axes.ravel()
    
    ax[0].imshow(ihc_rgb)
    ax[0].set_title("Original image")
    
    ax[1].imshow(ihc_hed[:, :, 0], cmap=cmap_hema)
    ax[1].set_title("Hematoxylin")
    
    ax[2].imshow(ihc_hed[:, :, 1], cmap=cmap_eosin)
    ax[2].set_title("Eosin")
    
    ax[3].imshow(ihc_hed[:, :, 2], cmap=cmap_dab)
    ax[3].set_title("DAB")
    
    for a in ax.ravel():
        a.axis('off')
    
    
    h = rescale_intensity(ihc_hed[:, :, 0], out_range=(0, 1))
    d = rescale_intensity(ihc_hed[:, :, 2], out_range=(0, 1))
    zdh = np.dstack((np.zeros_like(h), d, h))
    
    fig = plt.figure()
    axis = plt.subplot(1, 1, 1, sharex=ax[0], sharey=ax[0])
    axis.imshow(zdh)
    axis.set_title("Stain separated image (rescaled)")
    axis.axis('off')
    plt.show()
Beispiel #4
0
def test_immunohistochemistry():
    """ Test that "immunohistochemistry" image can be loaded. """
    data.immunohistochemistry()
Beispiel #5
0
.. [2] Irving, Benjamin. "maskSLIC: regional superpixel generation
    with application to local pathology characterisation in medical
    images.", 2016, , :arXiv:`1606.09518`

"""

import matplotlib.pyplot as plt

from skimage import data
from skimage import color
from skimage import morphology
from skimage import segmentation

# Input data
img = data.immunohistochemistry()

# Compute a mask
lum = color.rgb2gray(img)
mask = morphology.remove_small_holes(
    morphology.remove_small_objects(lum < 0.7, 500), 500)

mask = morphology.opening(mask, morphology.disk(3))

# SLIC result
slic = segmentation.slic(img, n_segments=200, start_label=1)

# maskSLIC result
m_slic = segmentation.slic(img, n_segments=100, mask=mask)

# Display result
The IHC staining expression of the FHL2 protein is here revealed with
Diaminobenzidine (DAB) which gives a brown color.


.. [1] A. C. Ruifrok and D. A. Johnston, "Quantification of histochemical
       staining by color deconvolution.," Analytical and quantitative
       cytology and histology / the International Academy of Cytology [and]
       American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

"""
import matplotlib.pyplot as plt

from skimage import data
from skimage.color import rgb2hed

ihc_rgb = data.immunohistochemistry()
ihc_hed = rgb2hed(ihc_rgb)

fig, axes = plt.subplots(2,
                         2,
                         figsize=(7, 6),
                         sharex=True,
                         sharey=True,
                         subplot_kw={'adjustable': 'box-forced'})
ax = axes.ravel()

ax[0].imshow(ihc_rgb)
ax[0].set_title("Original image")

ax[1].imshow(ihc_hed[:, :, 0], cmap=plt.cm.gray)
ax[1].set_title("Hematoxylin")
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self._main = QWidget()
        self.setCentralWidget(self._main)

        # Main menu bar
        self.menu = self.menuBar()
        self.menu_file = self.menu.addMenu("File")
        exit = QAction("Exit", self, triggered=qApp.quit)
        self.menu_file.addAction(exit)

        self.menu_about = self.menu.addMenu("&About")
        about = QAction("About Qt", self, shortcut=QKeySequence(QKeySequence.HelpContents),
                        triggered=qApp.aboutQt)
        self.menu_about.addAction(about)

        # Create an artificial color close to the original one
        self.ihc_rgb = data.immunohistochemistry()
        self.ihc_hed = rgb2hed(self.ihc_rgb)

        main_layout = QVBoxLayout(self._main)
        plot_layout = QHBoxLayout()
        button_layout = QHBoxLayout()
        label_layout = QHBoxLayout()

        self.canvas1 = FigureCanvas(Figure(figsize=(5, 5)))
        self.canvas2 = FigureCanvas(Figure(figsize=(5, 5)))

        self._ax1 = self.canvas1.figure.subplots()
        self._ax2 = self.canvas2.figure.subplots()

        self._ax1.imshow(self.ihc_rgb)

        plot_layout.addWidget(self.canvas1)
        plot_layout.addWidget(self.canvas2)

        self.button1 = QPushButton("Hematoxylin")
        self.button2 = QPushButton("Eosin")
        self.button3 = QPushButton("DAB")
        self.button4 = QPushButton("Fluorescence")

        self.button1.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        self.button2.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        self.button3.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        self.button4.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)

        self.button1.clicked.connect(self.plot_hematoxylin)
        self.button2.clicked.connect(self.plot_eosin)
        self.button3.clicked.connect(self.plot_dab)
        self.button4.clicked.connect(self.plot_final)

        self.label1 = QLabel("Original", alignment=Qt.AlignCenter)
        self.label2 = QLabel("", alignment=Qt.AlignCenter)

        font = self.label1.font()
        font.setPointSize(16)
        self.label1.setFont(font)
        self.label2.setFont(font)

        label_layout.addWidget(self.label1)
        label_layout.addWidget(self.label2)

        button_layout.addWidget(self.button1)
        button_layout.addWidget(self.button2)
        button_layout.addWidget(self.button3)
        button_layout.addWidget(self.button4)

        main_layout.addLayout(label_layout, 2)
        main_layout.addLayout(plot_layout, 88)
        main_layout.addLayout(button_layout, 10)

        # Default image
        self.plot_hematoxylin()
Beispiel #8
0
    '''
	Arguments: 
        color_imgs - Dictionary of Color Images
	Returns: 
        Clusters of colors per image. 

	Fit KMeans to each class of images (here only 2) to get clusters of colors. 
	'''
    clusters = []
    for img in color_imgs.values():
        nrow, ncol, depth = img.shape
        lst_of_pixels = [
            img[irow][icol] for irow in range(nrow) for icol in range(ncol)
        ]
        X = np.array(lst_of_pixels)

        sklearn_km = KMeans(n_clusters=3)
        result = sklearn_km.fit_predict(X)
        clusters.append(sklearn_km.cluster_centers_)

    return clusters


if __name__ == '__main__':

    ihc_rgb = data.immunohistochemistry()  # sample from library
    ihc_hed = dye_color_separation(ihc_rgb)
    ax = plot_dye_separation(ihc_rgb, ihc_hed)

    rescaled_img = rescale_dye_signals(ihc_hed, ax)
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 25 20:15:14 2018

@author: Xiaopeng
"""

import numpy as np
from skimage import io, data, color
img = data.coffee()
cutp = img[100:200, 300:400, :]
#裁剪图片
io.imsave('C:\\Users\\Xiaopeng\\Desktop\\Picture\\coffeeCut.jpg', cutp)
#对图片特定部分赋值
img[40:70, :] = img[350:380, :]
io.imsave('C:\\Users\\Xiaopeng\\Desktop\\Picture\\coffee=.jpg', img)

#对图片进行二值化
picture = data.immunohistochemistry()
img_grey = color.rgb2grey(picture)
print(img_grey.shape)
rows, cols = img_grey.shape
for i in range(rows):
    for j in range(cols):
        if img_grey[i, j] <= 0.5:
            img_grey[i, j] = 0
        else:
            img_grey[i, j] = 1
io.imshow(img_grey)
io.imsave('C:\\Users\\Xiaopeng\\Desktop\\Picture\\separate.jpg', img_grey)
"""
import matplotlib.pyplot as plt

from skimage import data
from skimage.color import rgb2hed
from matplotlib.colors import LinearSegmentedColormap

# Create an artificial color close to the original one
cmap_hema = LinearSegmentedColormap.from_list('mycmap', ['white', 'navy'])
cmap_dab = LinearSegmentedColormap.from_list('mycmap', ['white',
                                             'saddlebrown'])
cmap_eosin = LinearSegmentedColormap.from_list('mycmap', ['darkviolet',
                                               'white'])

ihc_rgb = data.immunohistochemistry()
ihc_hed = rgb2hed(ihc_rgb)

fig, axes = plt.subplots(2, 2, figsize=(7, 6), sharex=True, sharey=True)
ax = axes.ravel()

ax[0].imshow(ihc_rgb)
ax[0].set_title("Original image")

ax[1].imshow(ihc_hed[:, :, 0], cmap=cmap_hema)
ax[1].set_title("Hematoxylin")

ax[2].imshow(ihc_hed[:, :, 1], cmap=cmap_eosin)
ax[2].set_title("Eosin")

ax[3].imshow(ihc_hed[:, :, 2], cmap=cmap_dab)
    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)
#io.imshow(filter.gaussian_filter(e, 21))
#print np.mean(e)
plt.plot(exposure.histogram(e)[1], exposure.histogram(e)[0])

# <codecell>

io.imshow(filter.threshold_adaptive(e, 301, offset=0.025))

# <codecell>

io.imshow(A)

# <codecell>

from skimage import data
ihc = data.immunohistochemistry()
ihc_hdx = color.separate_stains(ihc, color.hdx_from_rgb)
ihc_rgb = color.combine_stains(ihc_hdx, color.rgb_from_hdx)

io.imshow(ihc_hdx[:,:,0])

# <codecell>

print [[0.644211, .835*0.716556, 0.266844], [0.092789, .835*0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]
io.imshow(color.separate_stains(A, 
    np.linalg.inv([[0.644211, 0.716556, 0.266844], [0.092789, 0.954111, 0.283111], [0.00001, 0.00001, 0.00001]]))[:, :, 2])



# <codecell>
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;
Beispiel #14
0
from skimage.segmentation import watershed

from scipy import ndimage as ndi

import matplotlib.pyplot as plt

import numpy as np
#%% example of a local image

image = imread("./images/coast_arnat59.jpg")
plt.imshow(image)
plt.imshow(rgb2gray(image), cmap="gray")

#%% example of loading image from the data module

image = data.immunohistochemistry()
plt.imshow(image)
image = rgb2gray(image)
plt.imshow(image, cmap="gray")
#plt.savefig('original.png')

#%% thresholding example (global thresholds): thresholding is used to segment images

#can threshold only gray images
fig, ax = try_all_threshold(image, verbose=False)
plt.show()

#%% apply minimum thresholding algorithm (performs better than other global thresholds algorithms)

thresh_min = threshold_minimum(image)
binary_min = image > thresh_min