Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!d62g2000hsf.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: machine vision-Color Matching
Date: Wed, 27 Feb 2008 20:32:44 -0800 (PST)
Organization: http://groups.google.com
Lines: 121
Message-ID: <c579d6e7-3bd8-4dc6-bd43-f3ba39438b2b@d62g2000hsf.googlegroups.com>
References: <fpgn52$9ij$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.67.199
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1204173164 32742 127.0.0.1 (28 Feb 2008 04:32:44 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 28 Feb 2008 04:32:44 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d62g2000hsf.googlegroups.com; posting-host=75.186.67.199; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
Bytes: 5838
Xref: news.mathworks.com comp.soft-sys.matlab:454224


On Feb 20, 3:08=A0am, "Vihang Patil" <vihang_pa...@yahoo.com> wrote:
> 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 =3D [18 22 25];
> silver =3D [179 185 191];
> red =3D [123 3 10];
> blue =3D [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 =A0value which is say
>
> color =3D [80 110 217];
> My question is "How do we determine and tell that it is
> blue"
> or if I get
> color =3D [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 =3D color(1) + color(2) + color(3) =3D (80 + 110
> +217) =3D 407
> 2. Do the summation of all the stored colors by the same
> way and do subtraction.
> ex:
> Blackval =3D black(1) + black(2) + black(3) =3D 65;
> Similarly other color will be;
> Redval =3D 126;
> Silverval =3D 555;
> Blueval =3D 408
> 3. Subtract testimageval from each of the colorval and the
> minimum value which corresponds to that color is the color
> detected.
> i.e
> =A0abs(407 - 65) =3D 342;
> abs(407-126) =3D 281;
> abs(407 -555) =3D 148
> abs(407 - 408) =3D 1 =3D ----> 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?
> =A0I 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

Vihang:
Here's an eye opening experience for you:
Download ImageJ and install it - it's freeware from the NIH.
http://rsb.info.nih.gov/ij/
Then go here
http://rsb.info.nih.gov/ij/plugins/color-inspector.html
and install the 3D Color Inspector/Color Histogram.
This amazing gamut visualization program lets you visualize the color
gamut in several different color spaces.  You read in your color image
and it plots the gamut scatterplot in 3D and lets you interact with it
in several ways, such as reorienting the axes.  It's really amazing
how much you can learn when you see what colors you actually have in
your image displayed graphically in a 3D scatterplot.  Plus it lets
you pick several color classifiers such as Median Cut, and Wu's color
quantization.  You can even specify the number of colors you wish to
classify your gamut into.

You can still do the math in MATLAB, but once you've visualized the
gamut of your image(s), I know you'll be glad you did.  It really
helps you to figure out how you need to carve up your gamut to do your
color classification.

Seriously, do this (it's free, painless, and easy), and then let me
know how you like it.  You'll be glad you did.  It's really cool!
Best wishes,
ImageAnalyst