Clear Filters
Clear Filters

i have following code of image extraxtion but i got gray scale image output while giving input color image ,how could i get the color image output

1 view (last 30 days)
a=imread('new2.png');
c=zeros(35,57,3)
e=zeros(35,57,3)
for i=1:35; for j=1:57; if a(i,j,1)>233 if a(i,j,1)<254 c(i,j,1)=a(i,j,1);
for i=1:35;
for j=1:57;
if a(i,j,2)>25
if a(i,j,2)<30
c(i,j,2)=a(i,j,2);
for i=1:35;
for j=1:57;
if a(i,j,3)>35
if a(i,j,3)<40
c(i,j,3)=a(i,j,3);
end
end
end
end
end
end
end
end
end
end
end
end
e=logical(c) colormap(jet) image(e)

Accepted Answer

Image Analyst
Image Analyst on 6 Oct 2013
Edited: Image Analyst on 6 Oct 2013
I wouldn't do it that inefficient way at all. But that's another issue. Your problem is that you're casting your color image to a logical image, e, and then displaying that e instead of the color image c. Why are you doing that? Also, I apply a colormap after I've displayed the image, not before and I'm not sure if displaying an image will reinitialize the colormap.
I'd do it like this:
rgbImage=imread('new2.png');
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
binaryImageR = redChannel > 233;
binaryImageG = redChannel > 25 & redChannel < 30;
binaryImageB = blueChannel > 35 & blueChannel < 40;
% Display the binary images.
subplot(2, 3, 2);
imshow(binaryImageR);
title('Red Binary Image', 'FontSize', fontSize);
subplot(2, 3, 3);
imshow(binaryImageG);
title('Green Binary Image', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(binaryImageB);
title('Red Binary Image', 'FontSize', fontSize);
% Combine
binaryImage = binaryImageR & binaryImageG & binaryImageB;
subplot(2, 3, 5);
imshow(binaryImage);
title('Overall Binary Image', 'FontSize', fontSize);
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(binaryImage,class(rgbImage)));
subplot(2, 3, 6);
imshow(maskedRgbImage);
title('Masked Color Image', 'FontSize', fontSize);

More Answers (0)

Categories

Find more on Convert Image Type 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!