问题
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.
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.
回答1:
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()

来源:https://stackoverflow.com/questions/21618252/get-blue-colored-contours-using-scikit-image-opencv