RGB to grayscale conversion
2 views (last 30 days)
Show older comments
I have a RGB image and I want to convert it to gray scale, which was very easy for me but with my new images, the result is just a yellow page!! what should I do?
Adiff=A+A0;
I = rgb2gray(Adiff);
0 Comments
Answers (1)
DGM
on 23 Jun 2023
This is likely one of a few things unrelated to the conversion.
Either OP was working with integer-class images and truncated all (or most) of the data by adding arrays
A = imread('pout.tif'); % I, uint8
A = imadjust(A,[0 0.9],[0.5 1]); % image is relatively bright
B = fliplr(A); % another similar image
C = A + B; % all data is truncated to 255
image(C) % there's nothing left
... or they're using a colormap that's too short for the nominal range of values in the sum image. This is relevant, because circa 2018, the default figure colormap length was 64, not 256. My guess is that both of these problems were at play.
A = imread('pout.tif'); % I, uint8
A = A + 60;
image(A)
colormap(parula(64))
This isn't caused by using properly-scaled floats with image(), as that would have resulted in a blue image (assuming the colormap is parula()).
Similarly, this wouldn't have been caused if the sum were improperly-scaled float either, as rgb2gray() would have truncated the entire image at 1. If the result were fed to image(), it would be rendered as blue. If it were fed to imagesc(), it would be rendered as teal.
Since the method of display (image() vs imagesc()) is unknown and the class of the images and nature of prior operations is also unknown, this question was never answerable beyond these guesses. Likewise, there's not really any point in recommending a fix without knowing those details.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!