フィルターのクリア

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

8 ビュー (過去 30 日間)
Inderdeep Grewal
Inderdeep Grewal 2018 年 7 月 9 日
回答済み: KSSV 2018 年 7 月 9 日
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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by