Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: machine vision-Color Matching
Date: Wed, 20 Feb 2008 08:08:02 +0000 (UTC)
Organization: Konem Solutions
Lines: 94
Message-ID: <fpgn52$9ij$1@fred.mathworks.com>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203494882 9811 172.30.248.35 (20 Feb 2008 08:08:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 20 Feb 2008 08:08:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 842609
Xref: news.mathworks.com comp.soft-sys.matlab:452570



Hello All
I am in the process of developing machine vision system i 
Matlab, primarily to detect color change, "basic colors 
only and not shades".
This is what I have achieved so far, please let me know 
after going through the details below if there is 
something which probably missing the way I am developing 
it.

Preliminary Details:
1. The object to be detected for color change comes in the 
following 4 colors;Metallic BLOOD RED, Metallic BlACK, 
Metallic SILVER, Metallic BLUE. 
2. They are coming on the conveyor at a speed about 1.25 
to 1.66 objects/min, ie roughly 600 - 800 in an 8 hour 
shift.
3. Ligting condition is flouroscent tube

My steps for Reference Image:
1. I have placed a trigger on the conveyor such that, 
whenever the object crosses it, the camera will take an 
image
2. I crop the Region of Interest and Store the image 
details of the part of my interest.
3. Convert the cropped image into indexed image for ex: 
rgb2ind(img,1,'nodither'); so that I have a single uniform 
colored image
4. Get the value of the color from the centroid of the 
cropped image.
5. Store the details of the 4 colors in the mat file for 
further testing process.

Testing Part:
1. I take the image and do the same analysis as discussed 
in Step 1 to 4 of the above discussion.
2. Then do the color matching part.
My logic here as descibed by the example below

Suppose I have got these values for the colors from the 
reference image

black = [18 22 25];
silver = [179 185 191];
red = [123 3 10];
blue = [75 96 237];

Now it is pretty obvious that due to the ambient lighting 
condition and other factors, you will not get the same 
color match or perfect match for the object in test 
condition and I get a  value which is say

color = [80 110 217]; 
My question is "How do we determine and tell that it is 
blue"
or if I get
color = [194 208 211], "How do I determing that it is 
Silver".

I hope I am able to explain or let you all visualize the 
problem.

My logic tells me that I should do the following
1. testimgval = color(1) + color(2) + color(3) = (80 + 110 
+217) = 407
2. Do the summation of all the stored colors by the same 
way and do subtraction.
ex:
Blackval = black(1) + black(2) + black(3) = 65;
Similarly other color will be; 
Redval = 126;
Silverval = 555;
Blueval = 408
3. Subtract testimageval from each of the colorval and the 
minimum value which corresponds to that color is the color 
detected.
i.e
 abs(407 - 65) = 342;
abs(407-126) = 281;
abs(407 -555) = 148
abs(407 - 408) = 1 = ----> least from all above so the 
color must be Blue.

But I some how dont get the same satisfactory results by 
my above calculation. i.e sometimes I get blue when the 
object is actually silver, I get red if the object is 
black and so on and so forth. 
Am I missing something very imp in designing this machine 
vision system?
 I know its not directly related to Matlab in any way, but 
just looking for some imp comments from those, who feel 
probably there is something which is still required there.
Thanks
Vihang