使用scikit-image/opencv获取蓝色轮廓 [英] Get blue colored contours using scikit-image/opencv
问题描述
我正在尝试使用scikit-image获得蓝色的轮廓.我确定opencv中有一些功能也可以在scikit-image中使用.
I'm trying to get blue colored contours using scikit-image. I'm sure there are functions in opencv that are also available in scikit-image.
我知道find_contours方法效果很好,但是它获得了所有轮廓颜色.我只是想得到蓝色的轮廓.
I am aware of the find_contours method which works well however it gets ALL colors of contours. I just wnat to get the blue contours.
http://scikit-image.org/docs/dev/api/skimage.measure.find_contours.html
有关如何执行此操作的任何想法?我的猜测是要以某种方式对图像进行预处理,以去除蓝色以外的所有颜色.
Any ideas of how to do this? My guess is to preprocess the image somehow to remove every color other than blue.
推荐答案
您建议先取消所有其他颜色的建议.这是执行此操作的一些代码:
Your suggestion of first suppressing all other colors is a good one. Here's some code for doing that:
from skimage import io, color, exposure, img_as_float
import matplotlib.pyplot as plt
# http://www.publicdomainpictures.net/view-image.php?image=26890&picture=color-wheel
image = img_as_float(io.imread('color-wheel.jpg'))
blue_lab = color.rgb2lab([[[0, 0, 1.]]])
light_blue_lab = color.rgb2lab([[[0, 1, 1.]]])
red_lab = color.rgb2lab([[[1, 0, 0.]]])
image_lab = color.rgb2lab(image)
distance_blue = color.deltaE_cmc(blue_lab, image_lab, kL=0.5, kC=0.5)
distance_light_blue = color.deltaE_cmc(light_blue_lab, image_lab, kL=0.5, kC=0.5)
distance_red = color.deltaE_cmc(red_lab, image_lab, kL=0.5, kC=0.5)
distance = distance_blue + distance_light_blue - distance_red
distance = exposure.rescale_intensity(distance)
image_blue = image.copy()
image_blue[distance > 0.3] = 0
f, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(20, 10))
ax0.imshow(image)
ax1.imshow(distance, cmap='gray')
ax2.imshow(image_blue)
plt.show()
这篇关于使用scikit-image/opencv获取蓝色轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!