DISPLAY RED, GREEN & BLUE COMPONENTS OF RGB IMAGE

91 次查看(过去 30 天)
Hello, I want to display 3 images of red, blue & green component. I don't want to display the GRAYSCALE images. I tried following code:
X-imread('Hello.jpg');
R = X(:,:,1);
image(R), colormap([[0:1/255:1]', zeros(256,1), zeros(256,1)]), colorbar;
%Green Component
G = X(:,:,2);
figure;
image(G), colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]), colorbar;
%Blue component
B = X(:,:,3);
figure;
image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), colorbar;
but it gives me 3 images with background as Red, green & blue.. How can I display only Red component of RGB image [No Grayscales]
Thanks
  2 个评论
Walter Roberson
Walter Roberson 2022-3-19
A = [0:1/255:1];
B = (0:1/255:1);
isequal(A, B)
ans = logical
1
The line
A = [0:1/255:1];
to MATLAB means the same thing as
temporary = 0:1/255:1;
A = horzcat(temporary);
clear temporary
but horzcat() of a single variable returns the same thing as the input (but after having taken a little bit of time), so the functionality is the same as
A = 0:1/255:1;
but taking slightly more time.
There are differences between using () and [] brackets. For example,
[1 -2]
ans = 1×2
1 -2
(1 -2)
ans = -1
That is, inside [], in some combinations of spacing, the space can indicate end of an expression and beginning of the next element.

请先登录,再进行评论。

回答(5 个)

Walter Roberson
Walter Roberson 2012-4-15
X-imread('Hello.jpg');
R = X
R(:,:,2:3) = 0;
image(R);
pause(5);
G = X;
G(:,:,[1 3]) = 0;
image(G);
pause(5);
B = X;
B(:,:,1:2) = 0;
image(B);
pause(5);
  3 个评论
DGM
DGM 2022-4-24
To answer the "reverse process" question:
% assume that this is the "forward process"
X = imread('peppers.png');
R = X;
R(:,:,2:3) = 0;
G = X;
G(:,:,[1 3]) = 0;
B = X;
B(:,:,1:2) = 0;
montage({R G B},'size',[1 3]);
% now you have three RGB images called R,G, and B
% you could reassemble them directly:
RGB1 = cat(3,R(:,:,1),G(:,:,2),B(:,:,3));

请先登录,再进行评论。


Priyanka Johri
Priyanka Johri 2016-11-2
x = imread('Hello.jpg');
figure, imshow(x(:,:,1)); % Red component
figure, imshow(x(:,:,2)); % Green component
figure, imshow(x(:,:,3)); % Blue component
% Is this what you required?
  9 个评论
Image Analyst
Image Analyst 2021-6-27
@abdelatti errokhsy, What does "styb by stybe" mean? I have no idea what a styb or stybe is.
Walter Roberson
Walter Roberson 2021-6-27
I have a suspicion that they are asking for a line by line explanation of the code.

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-4-15
Not sure what you want. I guess my first answer would be to just not display the green and blue components and that would then "display only Red component." But I don't know what you mean when you say "No Grayscales." The red channel, or any color channel is simply a numerical array, and that is normally displayed as gray scale, though you can apply a pseudocolor look up table (colormap) like you did to make it appear in any tint or even combination of many different colors. But you don't want the red channel to appear red, like you're doing now, and you don't want it to appear in gray scale, so what do you want?
  13 个评论
Moe Makki
Moe Makki 2021-5-22
@Image Analyst how do i scan pixels of an image and then remove green and blue components if redValue is above 200

请先登录,再进行评论。


Shatha Ali.
Shatha Ali. 2020-10-17
i=imread('6.jpg');
red= i(:,:,1);
green=i(:,:,2);
blue=i(:,:,3);
black=i(:,:,0:0:0);
white=i(:,:,1:1:1);
black=zeros(size(i,1),size(i,2),'unit8');
just_red=cat(3,red,black,black);
just_green=cat(3,black,green,black);
just_blue=cat(3,black,black,blue);
just_black=cat(3,black,black,black);
just_white=cat(3,white,white,white);
picture(3,2,1),imshow(i);
picture(3,2,2),imshow(just_red);
picture(3,2,3),imshow(just_green);
picture(3,2,4),imshow(just_blue);
picture(3,2,5),imshow(just_black);
picture(3,2,6),imshow(just_white);

Dayangku Nur Faizah Pengiran Mohamad
编辑:Walter Roberson 2021-12-5
B = X(:,:,3);
figure;
image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), imwrite(B,colormap,'blueHello.jpg');
Hope this will helps you.

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by