To convert a grayscale image to a red image in MATLAB, you can first create a matrix of zeros with the same dimensions as the grayscale image, and then assign the grayscale image as the red channel of the new matrix. Here's an example code:
main.m305 chars12 lines
In the above code, we first read the grayscale image using the imread
function. We then create a new matrix red_img
using the zeros
function, with the same number of rows and columns as the grayscale image and 3 channels (corresponding to RGB color space). Finally, we assign the grayscale image as the red channel of the new matrix, and display the resulting red image using imshow
.
Note that in the resulting red image, the green and blue channels will have values of zero, resulting in a red-only image.
gistlibby LogSnag