How to find all regions of the same color?

13 views (last 30 days)
arman Yaraee
arman Yaraee on 21 Oct 2011
Commented: Stephen23 on 30 Nov 2015
Hi guys. I wrote a piece of code which finds all the points with the same color as I selected:
In this part we just find the coordinates of the required co
im = imread('Lighthouse.jpg');
n = 1;
figure, imshow(im)
[x,y] = ginput(n);
x = floor(x);
y = floor(y);
%colour(length(x),3);
colour = zeros(1,length(x),3, 'uint8');
for i=1:length(x)
for k=1:3
colour(1,i,k) = im(y(i),x(i),k);
end
end
%image(colour);
%axis off;
Now that I have the colour, I want to search the picture for all the points with the same colour.
[r,c,t] = size(im);
counter = 1;
for i=1:r
for j=1:c
if (im(i,j,:) == colour(1,1,:))
coordr(counter) = i;
coordc(counter) = j;
counter = counter+1;
end
end
end
This way I found all the points with the color the user selected! Now my problem is:
  1. it takes long time to process!!
  2. I want to select colors which are close to my color but I dunno the algorithm to do it! (this is my main problem) because the points which are found are not enough!
for example they are about 200 points in a big picture. they will be seen as dots! any ideas?

Answers (3)

Walter Roberson
Walter Roberson on 21 Oct 2011
John D'Errico has a MATLAB File Exchange contribution for Fuzzy Color Matching

Image Analyst
Image Analyst on 21 Oct 2011
arman: I suggest you abandon that approach and use my delta E based approach in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 That uses an industry standard method (delta E) for determining color difference. I believe it will do exactly what you want.
Walter, fuzzy color was one of the submissions that John removed and never replaced. As I recall it didn't do color segmentation anyway but was some sort of a name assignment scheme, though. I still have his code though. He says "Fuzzycolor is a tool for identifying the "color name" of any RGB intensity triad, i.e., sets of 3 color values....."

lya lya
lya lya on 28 Nov 2015
Dear Image Analyst,
Do you still have the Fuzzy Color code from John? If so, I hope you can share it with me.
Thanks.
  3 Comments
Stephen23
Stephen23 on 30 Nov 2015
You can also try my FEX submission, which identifies colornames based on RGB values but uses the "industry standard method (delta E) for determining color difference":
It also supports many standard sets of named colors, such as CSS, dvips, HTML, Kelly, MacBeth, MATLAB, Wolfram, X11, xcolor, xkcd,...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!