I'm trying to create a mask for an RGB image using skikit learn. I want to create a mask selecting only pixels which are equal to [0,10,0], ie 10 on green channel. And then show only those pixels. This should be straight-forward, akin to http://scikit-image.org/docs/dev/user_guide/numpy_images.html, but I'm struggling.
If image is a loaded jpg, I can do
mask = image == [0,10,0]
image = image[mask]
viewer = ImageViewer(image)
viewer.show()
However, I get:
TypeError: Invalid dimensions for image data
If I then print(mask), I realise that instead of a series of True and False for each pixel, I'm getting:
[[ True False True]
[ True False True]
[ True False True]
...,
[ True False True]
[ True False True]
[ True False True]]
Note that the 1st pixel in my image is black. So it appears what it's doing is comparing [0,0,0] with [0,10,0], and instead of raising False, it raises True,False,True.
This then appears to fail as a mask, because I have 3 masks for each pixel, I suppose!
Does anyone know a simple way to get this masking working with RGB images?
Thanks