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

1 view (last 30 days)
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!
  2 Comments
Walter Roberson
Walter Roberson on 1 Mar 2013
Is there a particular reason you choose saturation rather than hue?
Shizuka
Shizuka on 1 Mar 2013
Yes, hue didn't work, I didn't add an another image to avoid making the post too convoluted with links.
Thanks for the answer!

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Mar 2013
Edited: Walter Roberson on 1 Mar 2013
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.
  6 Comments
Shizuka
Shizuka on 2 Mar 2013
Ohh, I apologize, I didn't refresh before my message, and thus didn't see your beautiful solution! It works way better and faster than mine! Thanks a lot :D I have to study it a little more, but I already tested it and it's perfect.
regarding your maze solving script that you linked I was already using it! Ever since I discovered it a few days ago. I told you I love your scripts :P
Thanks a lot again, really, you solved a problem that I had almoost lost all hope!
I do have another question (that one regards the usage of your maze solving script), but I'm going to ask that in another post, because I believe this would be off topic here.
poongothai rajan
poongothai rajan on 23 Jun 2014
i just want to combine the above features and then have to use PCA for dimension reduction..if anyone know the idea can u please tell

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!