Path: news.mathworks.com!not-for-mail
From: "Ethan " <emontag.nospam@leuzeusa.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: machine vision-Color Matching
Date: Mon, 3 Mar 2008 15:31:08 +0000 (UTC)
Organization: Leuze Electronic Inc
Lines: 113
Message-ID: <fqh5js$if5$1@fred.mathworks.com>
References: <fpgn52$9ij$1@fred.mathworks.com>
Reply-To: "Ethan " <emontag.nospam@leuzeusa.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1204558268 18917 172.30.248.37 (3 Mar 2008 15:31:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 3 Mar 2008 15:31:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1029120
Xref: news.mathworks.com comp.soft-sys.matlab:455050


You are trying to use one number to represent color when you need more. 
You should read a little bit about color to understand the problem, but 
basically your colors are going to vary in 3 dimensions, so you should check 
color in 3 dimensions. If you have an issue with color tolerance, ie not all 
blues are the same blue - they have some variation that is tolerable, then you 
may need to go deeper into understanding color. Otherwise you can try 
looking at the distance in 3D of a measured color from the standard color 
(say in rgb) rather than the sum of the color coordinates. You can also 
simplify things a little by using reducing the color to 2 dimensions by 
normalizing (into an analog of chromaticity). That is, use r=R/(R+G+B), 
g=G/(R+G+B) where R, G, and B are the digital values and r and g are 
"chromaticities". Then you may be able to use 2D distances instead of 3D. But 
if real color is important, you may need to use a real color space that is 
associated with human color vision.

"Vihang Patil" <vihang_patil@yahoo.com> wrote in message 
<fpgn52$9ij$1@fred.mathworks.com>...
> 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
>