# Is it possible to keep only coloured parts in an image, removing all the rest (in greyscale)?

I would like to know if it is possible to keep only coloured parts (for example red eyes) from a b/w image, removing all the other parts not coloured (i.e. in grayscale or black and white). I was thinking of RemoveBackground or in using

mask=DeleteSmallComponents@
ColorNegate@DeleteSmallComponents@MorphologicalBinarize[img, ...],
DiskMatrix[...]


but it removes also the coloured parts.. Any suggestions?

Thank you for your time. I really appreciate your help. Please find below an example of picture.

• Yes, it's possible. More people would be willing to show you how if you would provide a sample picture for people to work with. Sep 23 '19 at 17:21
• Sorry, C.E.. I thought I was adding it on the post, but I did not click on add at the end.
– Val
Sep 23 '19 at 18:05

First, let's split this image into three channels: hue, saturation, and brightness.

img = Import["https://i.stack.imgur.com/qwwmp.jpg"];
{h, s, b} = ColorSeparate[img, "HSB"]


It turns out that the leave has a much higher saturation than the black and white background. By using Binarize, we can create a white mask for the region that the leave covers. And finally, we get this:

ImageMultiply[img, Binarize[s]]


• Thanks C.E.. I did not think to separate the colour, but only to remove the background. Thank you very much. The result is awesome!
– Val
Sep 23 '19 at 18:35