MATLAB Answers

0

convert gray image back to rgb

zzz 님이 질문을 제출함. 14 Mar 2013
최근 활동 Walter Roberson 님이 댓글을 추가함. 18 Nov 2016
how to back grat to rgb gray2rgb function not found

  댓글 수: 0

로그인 to comment.

답변 수: 4

Answer by Image Analyst
on 14 Mar 2013
 Accepted Answer

If you have a color map - a mapping of what intensity should go to what color, like what imread() or rgb2ind() can give you - then you can use ind2rgb.
rgbImage = ind2rgb(grayImage, colormap);
Otherwise use
rgbImage = cat(3, grayImage, grayImage, grayImage);
grayImage needs to be in the range 0-255 uint8 if you want to display it.

  댓글 수: 0

로그인 to comment.


Answer by Shaun VanWeelden on 14 Mar 2013

Alternatively
rgb=img(:,:,[1 1 1]); does the same thing as Jan's, but is a little shorter maybe and easier to remember. img is your image you want to convert to rgb obviously

  댓글 수: 4

표시 이전 댓글 수: 1
It will become an RGB image whose colors all happen to be gray.
My tests show that if you take all possible RGB values and convert them to gray, that on average 65536 different combinations map to each value. 7 combinations map to complete black and 7 map to complete white; there are four shades that are created by 111642 different combinations. Clearly it is not possible to take a grayscale image and map it back to "the" original color.
rgb=img(:,:,[1 2 3]);
Image Analyst
on 18 Nov 2016
No, that throws an error if img is a gray scale image since there is no third dimension for gray scale images.

로그인 to comment.


Answer by Jan
on 14 Mar 2013

Asking Google for "Matlab gray2rgb" would be a good idea.
But a general method is:
RGB = cat(3, Gray, Gray, Gray);

  댓글 수: 2

it can work some time
No, this always works for gray images.
What it does not work for is
  • pseudocolor images: use ind2rgb for those
  • black and white images represented as datatype logical and for which the converted image is to be displayed using imshow() instead of image(): for those either use image() or use double() on the result of the cat()

로그인 to comment.


Answer by shehbaz Ali on 14 Mar 2013

This is not possible to to convert black and white image to gray image. Because you don't what will be colors of any pixel for rgb picture.

  댓글 수: 2

black and white to grayscale is easy, gray=uint8(bw.*254+1), and to convert that to rgb just do one of the other answers
gray = uint8(bw*255);
or
gray = double(bw);

로그인 to comment.



Translated by