Converting an image with specific values to black and white

조회 수: 1 (최근 30일)
med-sweng
med-sweng 2013년 4월 27일
I have an image that has only three values(i.e; 56, 98, 170). Those values represent different labels. How can I convert such image to only black and white without graylevels?
This may exapnad to having 4-vaues, 5-values, ...etc.
But, I think that if a solution was gained for three values, this could be applied to more than three value.
Thanks.
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 4월 27일
Which of the values should be converted to black, and which to white? Or do you want a three-level output?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 4월 27일
bwimage = (YourImage == 170);
This assumes that 56 and 98 are both to convert to black. If the constants such as 170 are really floating point values such as .539 then you will need to modify slightly; see http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Community Treasure Hunt

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

Start Hunting!

Translated by