如何选择图像中的不规则形状

时间:2017-03-31 07:14:43

标签: image image-processing image-segmentation

使用python代码,我们可以创建图像片段,如屏幕截图所示。我们的要求如何选择图像中的特定片段并应用不同的颜色?

Image

以下是我们的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()

2 个答案:

答案 0 :(得分:0)

这样做:

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

答案 1 :(得分:0)

您可以使用OpenCV python module - example