MATLAB: How to filter an RGB image and transform into an BW one.

imageimage analysisimage processingImage Processing ToolboxMATLAB

I have been trying to do that:
http://prntscr.com/umv66 -> http://goo.gl/Bgmv2 (You can ignore the red lines, I just added them to illustrate the final objective)
So, what I've done in the first case was: I transformed rgb -> hsv and picked up the s channel (a.k.a saturation). Then I used Otsu (called graythresh in matlab) to binarize and transform into a black and white picture. Everything worked perfectly.
Now, in the second case this doesn't work so well:
Base img( http://goo.gl/OtK4G) -> S Channel( http://goo.gl/oo8h6>) ->Otsu( http://goo.gl/cnfxU)
As you can see, the Otsu filter becomes useless in this case. Is there any workaround or other way I should be taking? Thanks in advance!

Best Answer

I think you need to try some noise removal first. You can try a median filter first because it's easy. If that doesn't work, try a bilateral filter or a mean shift filter. After that you should be able to threshold it reasonably well in the Saturation channel. If you look at the image's 3D color gamut you'll see that it is like a slab but it's not radial along a constant hue - it's tilted in the Hue-Saturation plane, so to do the best job of segmentation you'll need to do principal components analysis and find the axis and then threshold in the PC2 or PC3 component. You could do the PCA in either RGB color space or HSV colorspace. However, if you look at it in LAB color space, it's pretty much has a constant "b" value with varying "a" value. So use makecform to convert to lab colorspace and threshold the "a" channel, after noise reduction of course. That would be my recommendation after inspecting the gamut with this.