Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing Two Images

Hi All,

I need to compare two images to detect if they are identical. This algorith
needs to work for gray scale and colour.

What I have done for gray scale is use a compare function (with clear if 😃
and then perform a histrogram function on the resulting image. I then check
the distrubution of the 1 to 255 elements to see if they have any pixels.
If they do I know the images are not the same.

With a colour image I perform the compare function on each colour. Add the
resulting images and then run the histogram method.

This function seems to work OK but I can't help thinking there must be an
easier methode for achieving this.

Does anyone have any ideas?

Thanks.

Denis
0 Kudos
Message 1 of 4
(4,211 Views)
Hi Denis,

This sounds like a reasonable method to me, although I don't see that you necessarily need to process the color images on a per plane basis. You could use the IMAQ Absolute Difference followed by IMAQ Threshold and IMAQ Quantify. For color images substitute IMAQ Color Threshold.

The IMAQ Absolute Difference function will accept color or mono images. Also, both the IMAQ Threshold and IMAQ Color Threshold return an 8 bit mono type, which is compatible with the IMAQ Quantify function.

There probably is a way to do this for mono and color images without changing any functions, but I can't think of one that would actually be *easier* than the method you have already described.

Cheers,
Brent R.
0 Kudos
Message 2 of 4
(4,211 Views)
Hi Brent,

thanks for your input. I implemented your method and it works fine.
However I did some timing test and came up with the following observations:

Method 1 Method 2
8bit Images Fastest
16bit Images Fastest
Float Images Fastest
Complex Image --- Not Supported ---
RGB Image Equal Equal
HSL Very Slow Not Supported

I find it interesting that the method I suggested typically executes quicker
then the one you suggested. Additionally my method supports HSL (this might
not be important - I've never had to use HSL.

I have include these finding for your benefit, and anyone else that might
have an interest in this t
opic.

I have included my source code in case anyone would like to look at it. If
anyone has any thoughts or alterations, I would be interested in hearing
them.

Thanks

Denis




[Attachment Test.llb, see below]
0 Kudos
Message 3 of 4
(4,211 Views)
Hi Denis,

Thanks. This is good information to know. If ultimate speed is your goal, then your might be able to speed thing up by doing a bit-wise comparison of the pixel values with lower level memory routines. You can use IMAQ GetImagePixelPtr.vi to get a pointer the image's location in memory. Pass this to an external routine that interates through both images and compares (XOR) the values. If you only care that the images are different and not *how* they are different, then the routine could just return a single boolean as soon as the first mismatch is found. With some idea about how you expect the image to chage (ex. object entering lower, left corner of FOV), an intelligent search routine might greatly speed up the process.

Cheers,

Brent R.
0 Kudos
Message 4 of 4
(4,211 Views)