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

5 次查看(过去 30 天)
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?

采纳的回答

KSSV
KSSV 2018-7-9
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by