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
2022년 3월 19일
A = [0:1/255:1];
B = (0:1/255:1);
isequal(A, B)
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]
(1 -2)
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
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
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
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
2021년 6월 27일
@abdelatti errokhsy, What does "styb by stybe" mean? I have no idea what a styb or stybe is.
Walter Roberson
2021년 6월 27일
I have a suspicion that they are asking for a line by line explanation of the code.
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
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
Image Analyst
2021년 5월 22일
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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/383753/image.png)
댓글 수: 0
Dayangku Nur Faizah Pengiran Mohamad
2021년 12월 5일
편집: 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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!