楼主: Nicolle
263 14

Scikit-Image User Guide [推广有奖]

版主

巨擘

0%

还不是VIP/贵宾

-

TA的文库  其他...

Python Programming

SAS Programming

Structural Equation Modeling

威望
15
论坛币
12197625 个
学术水平
2693 点
热心指数
2573 点
信用等级
2494 点
经验
411529 点
帖子
16674
精华
73
在线时间
6291 小时
注册时间
2005-4-23
最后登录
2018-2-25

Nicolle 学生认证  发表于 2018-2-15 02:10:06 |显示全部楼层

本帖被以下文库推荐

stata SPSS
Nicolle 学生认证  发表于 2018-2-15 02:16:42 |显示全部楼层
Image Segmentation
Image segmentation is the task of labeling the pixels of objects of interest in an image.

In this tutorial, we will see how to segment objects from a background. We use the coins image from skimage.data. This image shows several coins outlined against a darker background. The segmentation of the coins cannot be done directly from the histogram of grey values, because the background shares enough grey levels with the coins that a thresholding segmentation is not sufficient.
  1. >>> import numpy as np
  2. >>> from skimage import data
  3. >>> coins = data.coins()
  4. >>> histo = np.histogram(coins, bins=np.arange(0, 256))

  5. Edge-based segmentation
  6. >>> from skimage.feature import canny
  7. >>> edges = canny(coins/255.)

  8. >>> from scipy import ndimage as ndi
  9. >>> fill_coins = ndi.binary_fill_holes(edges)

  10. >>> label_objects, nb_labels = ndi.label(fill_coins)
  11. >>> sizes = np.bincount(label_objects.ravel())
  12. >>> mask_sizes = sizes > 20
  13. >>> mask_sizes[0] = 0
  14. >>> coins_cleaned = mask_sizes[label_objects]

  15. Region-based segmentation
  16. >>> markers = np.zeros_like(coins)
  17. >>> markers[coins < 30] = 1
  18. >>> markers[coins > 150] = 2

  19. >>> from skimage.filters import sobel
  20. >>> elevation_map = sobel(coins)

  21. >>> markers = np.zeros_like(coins)
  22. >>> markers[coins < 30] = 1
  23. >>> markers[coins > 150] = 2

  24. >>> from skimage.morphology import watershed
  25. >>> segmentation = watershed(elevation_map, markers)

  26. >>> segmentation = ndi.binary_fill_holes(segmentation - 1)

  27. >>> labeled_coins, _ = ndi.label(segmentation)
复制代码


回复

使用道具 举报

Nicolle 学生认证  发表于 2018-2-15 02:17:41 |显示全部楼层

How to parallelize loops

本帖最后由 Nicolle 于 2018-2-15 02:26 编辑
  1. How to parallelize loops
  2. In image processing, we frequently apply the same algorithm on a large batch of images. In this paragraph, we propose to use joblib to parallelize loops. Here is an example of such repetitive tasks:

  3. from skimage import data, color, util
  4. from skimage.restoration import denoise_tv_chambolle
  5. from skimage.feature import hog

  6. def task(image):
  7.     """
  8.     Apply some functions and return an image.
  9.     """
  10.     image = denoise_tv_chambolle(image[0][0], weight=0.1, multichannel=True)
  11.     fd, hog_image = hog(color.rgb2gray(image), orientations=8,
  12.                         pixels_per_cell=(16, 16), cells_per_block=(1, 1),
  13.                         visualise=True)
  14.     return hog_image


  15. # Prepare images
  16. hubble = data.hubble_deep_field()
  17. width = 10
  18. pics = util.view_as_windows(hubble, (width, hubble.shape[1], hubble.shape[2]), step=width)
  19. To call the function task on each element of the list pics, it is usual to write a for loop. To measure the execution time of this loop, you can use ipython and measure the execution time with %timeit.

  20. def classic_loop():
  21.     for image in pics:
  22.         task(image)


  23. %timeit classic_loop()
  24. Another equivalent way to code this loop is to use a comprehension list which has the same efficiency.

  25. def comprehension_loop():
  26.     [task(image) for image in pics]

  27. %timeit comprehension_loop()
  28. joblib is a library providing an easy way to parallelize for loops once we have a comprehension list. The number of jobs can be specified.

  29. from joblib import Parallel, delayed
  30. def joblib_loop():
  31.     Parallel(n_jobs=4)(delayed(task)(i) for i in pics)

  32. %timeit joblib_loop()
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-2-15 02:24:32 |显示全部楼层

Immunohistochemical staining colors separation

  1. Immunohistochemical staining colors separation
  2. Color deconvolution consists of the separation of features by their colors.

  3. In this example we separate the immunohistochemical (IHC) staining from the hematoxylin counterstaining. The separation is achieved with the method described in [1], known as “color deconvolution”.

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

  5. [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.
  6. import matplotlib.pyplot as plt

  7. from skimage import data
  8. from skimage.color import rgb2hed
  9. from matplotlib.colors import LinearSegmentedColormap

  10. # Create an artificial color close to the orginal one
  11. cmap_hema = LinearSegmentedColormap.from_list('mycmap', ['white', 'navy'])
  12. cmap_dab = LinearSegmentedColormap.from_list('mycmap', ['white',
  13.                                              'saddlebrown'])
  14. cmap_eosin = LinearSegmentedColormap.from_list('mycmap', ['darkviolet',
  15.                                                'white'])

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

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

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

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

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

  27. ax[3].imshow(ihc_hed[:, :, 2], cmap=cmap_dab)
  28. ax[3].set_title("DAB")

  29. for a in ax.ravel():
  30.     a.axis('off')

  31. fig.tight_layout()
复制代码
  1. Now we can easily manipulate the hematoxylin and DAB “channels”:

  2. import numpy as np

  3. from skimage.exposure import rescale_intensity

  4. # Rescale hematoxylin and DAB signals and give them a fluorescence look
  5. h = rescale_intensity(ihc_hed[:, :, 0], out_range=(0, 1))
  6. d = rescale_intensity(ihc_hed[:, :, 2], out_range=(0, 1))
  7. zdh = np.dstack((np.zeros_like(h), d, h))

  8. fig = plt.figure()
  9. axis = plt.subplot(1, 1, 1, sharex=ax[0], sharey=ax[0], adjustable='box-forced')
  10. axis.imshow(zdh)
  11. axis.set_title("Stain separated image (rescaled)")
  12. axis.axis('off')
  13. plt.show()
复制代码

回复

使用道具 举报

supercookie123 发表于 2018-2-15 02:28:13 |显示全部楼层
感謝分享
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

军旗飞扬 发表于 2018-2-15 05:39:22 |显示全部楼层
谢谢分享
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

啸傲江弧 发表于 2018-2-15 05:44:05 |显示全部楼层
谢谢楼主分享
回复

使用道具 举报

sqy 发表于 2018-2-15 07:18:53 |显示全部楼层
顶!!!!
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

hjtoh 发表于 2018-2-15 08:45:05 来自手机 |显示全部楼层
Nicolle 发表于 2018-2-15 02:10
User Guide
  • Getting started
  • A crash course on NumPy for images
  • 谢谢分享
    已有 1 人评分论坛币 收起 理由
    Nicolle + 20 鼓励积极发帖讨论

    总评分: 论坛币 + 20   查看全部评分

    回复

    使用道具 举报

    GKINGLIU 发表于 2018-2-15 08:54:34 来自手机 |显示全部楼层
    Nicolle 发表于 2018-2-15 02:10
    User Guide
  • Getting started
  • A crash course on NumPy for images
  • 不错哦
    已有 1 人评分论坛币 收起 理由
    Nicolle + 20 鼓励积极发帖讨论

    总评分: 论坛币 + 20   查看全部评分

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 我要注册

    GMT+8, 2018-2-25 04:06