Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display the red channel of an image in Matlab?

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?

like image 520
snakile Avatar asked Aug 23 '10 11:08

snakile


People also ask

What is red channel in image?

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 .

How do I display the RGB image in MATLAB?

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 .

What is color channel image?

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.


2 Answers

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.

like image 119
ypnos Avatar answered Oct 14 '22 03:10

ypnos


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);
like image 39
harja Avatar answered Oct 14 '22 03:10

harja