Problem 2542. Convert a grayscale image into RGB colour format, preserving data type
In the Image Processing Toolbox, MATLAB provides
rgb2gray
to convert a 3 channel color image into a 1 channel intensity (grayscale image). But not the other way around. Sometimes it is useful to have an intensity image represented in the 3 channel colour format.
Write a function to convert an input grayscale image into an equivalent RGB image, ensuring that the datatype of the input image matrix is preserved.
Example:
grayImg = [1 2 3; 4 5 6; 7 8 9]; rgbImg = gray2rgb(grayImg); rgbImg(:,:,1) = [1 2 3; 4 5 6; 7 8 9]; rgbImg(:,:,2) = [1 2 3; 4 5 6; 7 8 9]; rgbImg(:,:,3) = [1 2 3; 4 5 6; 7 8 9];
Solution Stats
Problem Comments
-
1 Comment
Really, you need to add more test cases. You're not even testing that your condition of 'ensuring that the datatype of the input image matrix is preserved' has been fulfilled.
Solution Comments
Show commentsProblem Recent Solvers33
Suggested Problems
-
Convert a numerical matrix into a cell array of strings
1830 Solvers
-
598 Solvers
-
Find the area of a rectangle if length of the diagonal is given.
165 Solvers
-
1203 Solvers
-
Matlab Basics - Convert a row vector to a column vector
628 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!