r g b components of an image
59 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Image Analyst
2013-10-22
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.
0 个评论
更多回答(2 个)
sixwwwwww
2013-10-21
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!
0 个评论
mithlesh arya
2017-8-21
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!