How can I reverse black and white in a grayscale image?

조회 수: 469(최근 30일)
I have a grayscale image and I'm trying to reverse the black and white in it as an exercise. I think I'm supposed to use for loops in some way to access the colormap so the entire image matrix is composed of 1's and 0's (at which point I could switch the two by subtracting 1 from all values) but I don't know how to get this matrix in the first place. Thank you!
  댓글 수: 2
Cedric Wannaz
Cedric Wannaz 2014년 7월 2일
편집: Cedric Wannaz 2014년 7월 2일
And here is a second hint:
>> I = imread('board.tif');
>> J = rgb2gray(I);
>> size(J)
ans =
648 306
>> min(J(:))
ans =
0
>> max(J(:))
ans =
255
so pixels' "grayscale" level seem to be coded with (unsigned) integers in the range 0 to 255.
Note that you can visualize J with
>> imshow( J ) ;
Now maybe there is an operation that you could perform on J which would reverse the scale ..

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

채택된 답변

Image Analyst
Image Analyst 2014년 7월 2일
Try this
inverseGrayImage = uint8(255) - grayImage;
  댓글 수: 1
Mark Quesada
Mark Quesada 2019년 3월 26일
You animal, that was spot on; Worked right out of the gate!

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

추가 답변(1개)

Roche de Guzman
Roche de Guzman 2021년 1월 14일
I = imcomplement(I)
  댓글 수: 1
Victor Mtsimbe Norrild
Victor Mtsimbe Norrild 2021년 3월 17일
You animal, that was spot on; Worked right out of the gate!

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

범주

Find more on Environment and Settings 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!

Translated by