r g b components of an image

54 visualizzazioni (ultimi 30 giorni)
shefali
shefali il 21 Ott 2013
Risposto: mithlesh arya il 21 Ago 2017
i=imread('car.jpg'); r=i(:,:,1); imshow(r); my result after this is a black and white image. instead it should display red component of the image.. please suggest something to get exact result.

Risposta accettata

Image Analyst
Image Analyst il 22 Ott 2013
That should work. The only reason it wouldn't is if i is a floating point array, in which case you'd have to use imshow(i, []) to see it. By the way, use a variable name other than i (the imaginary variable) for your image name, such as rgbImage or something descriptive like that. If you have a floating point image and values exceed 1 they will appear as white and if they are less than 0 they will appear as black. Not sure if you meant a black and white image like you said, or if you really meant a gray scale (monochrome) image that has 256 gray levels, not just 2 levels, those being pure black and pure white.
Of course you know that each color channel by itself is a gray scale image , don't you? In other words if I extract each color channel:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
each one of those arrays is just a simple monochrome gray scale array, and will appear as gray scale if you use imshow(). If you want to see it appear in the color of the color channel that it represents then you'd have to either use cat() to make an RGB image out of it:
z = zeros(size(redChannel));
redAppearingImage = cat(3, redChannel, z, z);
imshow(redAppearingImage);
or use colormap() to apply a color to it (which will use less memory).
imshow(redChannel);
myColorMap = [[0:255]', zeros(256,1), zeros(256,1)];
colormap(myColorMap);
colorbar;
Finally you might have fun running my RGB histogram demo attached below.

Più risposte (2)

sixwwwwww
sixwwwwww il 21 Ott 2013
Dear Shefali, one way to just show three separate color images is as follows:
img = imread('filename');
figure, imshow(img)
red = img(:,:,1);
green = img(:,:,2);
blue = img(:,:,3);
a = zeros(size(img, 1), size(img, 2));
just_red = cat(3, red, a, a);
figure, imshow(just_red)
just_green = cat(3, a, green, a);
figure, imshow(just_green)
just_blue = cat(3, a, a, blue);
figure, imshow(just_blue)
I hope it helps. Good luck!

mithlesh arya
mithlesh arya il 21 Ago 2017
In my image, I have lots of red cells..which are not useful for me...I want to remove these cells...how to remove these cells.

Community Treasure Hunt

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

Start Hunting!

Translated by