Clear Filters
Clear Filters

Converting an RGB image to black and white based on a user defined color scale?

5 views (last 30 days)
I have a 408x576x3 unit 8 image that I would have the user define a color range. If the RGB value is less than the defined range, the pixel is converted to the color black and all other pixels with RGB values greater than the defined range are converted to white.
An example in the image attached would to have (according to the color spectrum in the scale bar) anything form 0 to 0.02 become black and all else turned white.
Is there such a way to create and IF statement where the user can define a RGB value where anything equal to or less than becomes black, and all else is white?

Accepted Answer

KSSV
KSSV on 9 Jul 2018
You can use logical indexing with inequalities. Check the below example.
[X,Y,Z] = peaks(100) ;
Z(Z>=-2 & Z<=2) = 1 ;
Z(Z<=-2 | Z>=2) = 0 ;
pcolor(X,Y,Z)

More Answers (0)

Categories

Find more on Convert Image Type 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!