如何 select 图像中的不规则形状

How to select irregular shapes in a image

使用 python 代码,我们能够创建图像片段,如屏幕截图所示。我们的要求是 如何 select 图像中的特定部分并为其应用不同的颜色?

以下是我们的python片段

from skimage.segmentation import felzenszwalb, slic,quickshift

from skimage.segmentation import mark_boundaries

from skimage.util import img_as_float

import matplotlib.pyplot as plt

from skimage import measure

from skimage import restoration

from skimage import img_as_float

image = img_as_float(io.imread("leaf.jpg"))
segments = quickshift(image, ratio=1.0, kernel_size=20, max_dist=10,return_tree=False, sigma=0, convert2lab=True, random_seed=42)

fig = plt.figure("Superpixels -- %d segments" % (500))
ax = fig.add_subplot(1, 1, 1)

ax.imshow(mark_boundaries(image, segments))

plt.axis("off")
plt.show()

这样做:

seg_num = 64 # desired segment to be colored
color = float64([1,0,0]) # red color
image[segments == 64] = color # assign color to the segment

您可以使用 OpenCV python module - example