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

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

KSSV
KSSV il 9 Lug 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)

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by