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
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Image Analyst
2013-10-6
编辑:Image Analyst
2013-10-6
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);
更多回答(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!