rgbImage = grayImage / max(max(grayImage));
or
rgbImage = grayImage / 255;
Which of the above is right,and reason?
To convert a grayscale image to an RGB image, there are two issues you have to address:
double
uint8
class
Here are 3 typical conditions you might encounter:
To convert a uint8 or double grayscale image to an RGB image of the same data type, you can use the functions repmat or cat:
repmat
cat
rgbImage = repmat(grayImage,[1 1 3]); rgbImage = cat(3,grayImage,grayImage,grayImage);
To convert a uint8 grayscale image to a double RGB image, you should convert to double first, then scale by 255:
rgbImage = repmat(double(grayImage)./255,[1 1 3]);
To convert a double grayscale image to a uint8 RGB image, you should scale by 255 first, then convert to uint8:
rgbImage = repmat(uint8(255.*grayImage),[1 1 3]);
2.1m questions
2.1m answers
60 comments
57.0k users