Reputation: 2642
I just start to try MATLAB Project. I used to separate the Red, Green and Blue colors. This is my function:
function x = colorsep(b) %
n = 256; % color is from 0->255, so it has 256
a = imread('peppers.png');
b=im2uint8(a);
x=figure; % create picture to put the image
subplot(2,2,1); %(2 rows, 2column, cell ti 1)
imshow(b),title('Full Color');
colorlist = {'Red','Green','Blue'};
gr = 0:1/(n-1):1;
for k=1:3
cMap = zeros(n,3);
cMap(:,k) = gr;
subplot(2,2,k+1);
imshow(ind2rgb(b(:,:,k),cMap)); %ind2r = index to rgb
title(colorlist{k});
end
end
Now I want to separate three color ( Pink, Yellow, Orange), what will I do? Anyone know about this? Thanks so much.
Upvotes: 1
Views: 10013
Reputation: 20915
The question is incorrect. An image in the computer consists of 3 color channels
What you are doing here is showing a single channel, with a colormap that corresponds to it. By the way, the colormap is unnessecary, and you can show it like that (More natural)
function colorsep() %
a = imread('peppers.png');
colorlist = {'R','G','B'};
subplot(2,2,1);
imshow(a);
for k=1:3
subplot(2,2,k+1);
imshow( a(:,:,k));
title(colorlist{k});
end
end
If you want to separate it in another color space, you should first transform it to another color space - like LAB, and then show the channels separately.
If you want to find all "pink","yellow" objects, you should do a segmentation, and check objects mean color.
Please clarify what exactly you want.
Upvotes: 4