2010-08-23 1911 views
15

我有一个3D矩阵im它代表一个RGB图像。我能做如何在Matlab中显示图像的红色通道?

imshow(im) 

来显示图像。

我想一次仅显示一个RGB通道:我想显示红色通道,并且我希望它显示为红色。

我已经试过

imshow(im(:,:,1)) 

,但它显示的灰度图像(这是不是我想要的)。

如何显示红色通道并使其显示为红色?

+0

这里重要的是如果你想显示一个彩色图像,确保它的3维。如果你做im(:,:,1),你只剩下一个维度。 – saurabheights 2016-03-03 10:09:56

回答

19

我有三个建议给你。

1. 使用imagesc函数并选择红色调色板。

2. 清除其他颜色通道:im(:,:,2:3) = 0; imshow(im);

使用ind2rgb功能与您建立相应的彩色地图。

+0

谢谢。选择选项2 – snakile 2010-08-23 11:37:02

2

你是说你只想提取红色? 使用im(:,:,1)仅分离3D图像中的红色通道并将其转换为2D图像。 试试这个简单的代码:

im=imread('example.jpg'); 
im_red=im(:,:,1); 
im_gray=rgb2gray(im); 
im_diff=imsubtract(im_red,im_gray); 
imshow(im_diff); 
4

试试这个:

% 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); 
3

试试这个

I = imread('exemple.jpg'); 

%Red component 
R = I(:,:,1); 
image(R), colormap([[0:1/255:1]', zeros(256,1), zeros(256,1)]), colorbar; 

%Green Component 
G = I(:,:,2); 
figure; 
image(G), colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]), colorbar; 

%Blue component 
B = I(:,:,3); 
figure; 
image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), colorbar; 
0

为了更好的视野,你可以计算并显示纯色。式R p = R Ç /(R ç + G Ç + B Ç)。以及红色代码示例:

imagesc(im(:,:,1) ./ (im(:,:,1) + im(:,:,2) + im(:,:,3))) 

这样会使颜色显示更清晰,因为其他颜色已被滤除。

我会尝试用一个例子来说明它:

原始图像:

enter image description here

图像的红色通道(im(:,:,1)):

enter image description here

纯红色:

enter image description here

相关问题