Clear Filters
Clear Filters

DISPLAY RED, GREEN & BLUE COMPONENTS OF RGB IMAGE

180 views (last 30 days)
LOKESH
LOKESH on 15 Apr 2012
Commented: DGM on 24 Apr 2022
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 Comments
Andres Soto
Andres Soto on 19 Mar 2022
Try () instead of [] there [0:1/255:1]
Walter Roberson
Walter Roberson on 19 Mar 2022
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.

Sign in to comment.

Answers (5)

Walter Roberson
Walter Roberson on 15 Apr 2012
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 Comments
Walter Roberson
Walter Roberson on 21 Mar 2018
kranti kumar kuppili : what would the inputs be?
DGM
DGM on 24 Apr 2022
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));

Sign in to comment.


Priyanka Johri
Priyanka Johri on 2 Nov 2016
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 Comments
Image Analyst
Image Analyst on 27 Jun 2021
@abdelatti errokhsy, What does "styb by stybe" mean? I have no idea what a styb or stybe is.
Walter Roberson
Walter Roberson on 27 Jun 2021
I have a suspicion that they are asking for a line by line explanation of the code.

Sign in to comment.


Image Analyst
Image Analyst on 15 Apr 2012
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 Comments
Moe Makki
Moe Makki on 22 May 2021
@Image Analyst how do i scan pixels of an image and then remove green and blue components if redValue is above 200

Sign in to comment.


Shatha Ali.
Shatha Ali. on 17 Oct 2020
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
Edited: Walter Roberson on 5 Dec 2021
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.

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!