I have a 3D matrix im
which represents an RGB image. I can do
imshow(im)
to display the image.
I want to display only one of the RGB channels at a time: I want to display the red channel and I want it to appear red.
I've tried
imshow(im(:,:,1))
but it displays the grayscale image (which is not what I want).
How do I display the red channel and make it appear red?
For example, in the red channel image, the white represents the highest concentration of pure red values. As red becomes mixed with green or blue, gray pixels appear. The black region in the image shows pixel values that contain no red values, in other words, when R == 0 .
imshow( RGB ) displays the truecolor image RGB in a figure. imshow( BW ) displays the binary image BW in a figure. For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white. imshow( X , map ) displays the indexed image X with the colormap map .
Color digital images are made of pixels, and pixels are made of combinations of primary colors represented by a series of code. A channel in this context is the grayscale image of the same size as a color image, made of just one of these primary colors.
I have three proposals for you.
1.
Use the imagesc
function and choose a red color palette.
2.
Clear the other color channels: im(:,:,2:3) = 0; imshow(im);
3. Use the ind2rgb
function with a color map you build accordingly.
Try this:
% display one channel only
clear all;
im=imread('images/DSC1228L_512.jpg');
im_red = im;
im_green = im;
im_blue = im;
% Red channel only
im_red(:,:,2) = 0;
im_red(:,:,3) = 0;
figure, imshow(im_red);
% Green channel only
im_green(:,:,1) = 0;
im_green(:,:,3) = 0;
figure, imshow(im_green);
% Blue channel only
im_blue(:,:,1) = 0;
im_blue(:,:,2) = 0;
figure, imshow(im_blue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With