When I make my image grayscale the image shows up red, why is this?

8 views (last 30 days)
I use the following code to turn my image into grayscale but then most of the image turns out red for some reason. flower_gray_scale = 0.2989*double(flowerarrangement(:,:,1)) + 0.587*double(flowerarrangement(:,:,2)) + 0.114*double(flowerarrangement(:,:,3)); image(flower_gray_scale)

Accepted Answer

Image Analyst
Image Analyst on 8 Sep 2014
Edited: Image Analyst on 8 Sep 2014
It's because image() clips anything after 64 gray levels to the color of 64 gray levels. I just answered this today http://www.mathworks.com/matlabcentral/answers/153539#answer_151050. Run the demo there (also attached below this next demo). Also see this demo, and try using imshow instead of image(). Or try using jet(256) instead of the default jet(64) that image uses.
flowerarrangement = imread('peppers.png'); % Demo image.
flower_gray_scale = 0.2989*double(flowerarrangement(:,:,1)) + 0.587*double(flowerarrangement(:,:,2)) + 0.114*double(flowerarrangement(:,:,3));
image(flower_gray_scale);
% imshow(flower_gray_scale, []);
colormap(jet(256)); % colormap() uses jet(64) which is not good with image().
colorbar;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Bottom line, either
  1. Use imshow() instead of image(), or
  2. Use a 256 colormap if you're going to use image(), or
  3. Use colormap(gray(256)) if you want gray scale, not pseudocolored image.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!