'Labelling connected components of an image with scipy
Hello I am following this example for labelling connected components of an image. I understand how to measure and label the blobs seen in this link. However how do I actually select a certain component? For example if I wanted to use the blue blob seen in the code how do I select this and print that numpy array? Would it be something like print(label(x, connectivity=1))? 1 being the value that I get when hovering over the plot generated by the code.
https://scipy-lectures.org/packages/scikit-image/auto_examples/plot_labels.html
> from skimage import measure from skimage import filters import
> matplotlib.pyplot as plt import numpy as np
>
> n = 12 l = 256 np.random.seed(1) im = np.zeros((l, l)) points = l *
> np.random.random((2, n ** 2)) im[(points[0]).astype(np.int),
> (points[1]).astype(np.int)] = 1 im = filters.gaussian(im, sigma= l /
> (4. * n)) blobs = im > 0.7 * im.mean()
>
> all_labels = measure.label(blobs) blobs_labels = measure.label(blobs,
> background=0)
>
> plt.figure(figsize=(9, 3.5)) plt.subplot(131) plt.imshow(blobs,
> cmap='gray') plt.axis('off') plt.subplot(132) plt.imshow(all_labels,
> cmap='nipy_spectral') plt.axis('off') plt.subplot(133)
> plt.imshow(blobs_labels, cmap='nipy_spectral') plt.axis('off')
>
> plt.tight_layout() plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|