Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Pixel difference between two images?

1. ## Pixel difference between two images?

I am trying to calculate pixel difference count between two images ? Is there any function that TC provides for doing this?

I am using TC 6.20

Thanks
Manas

2. ## Re: Pixel difference between two images?

Not really, that I know of. However, you could use the Regions.compare to do it. Just send youself into a loop starting at a huge threshold (like 10000) and then decrease that number until it begins to fail. You can use some simple heuristics here too and maybe start by cutting it in half, then that in half, and so on until it fails, then do the same the other way until it passes again, then loop back the other way again, and so on until you've arrived at a final failed pixel count.

Make sense?

3. ## Re: Pixel difference between two images?

Hi Manas,

You can use the following code to count the actual number of differing pixels:

<font class="small">Code:</font><hr /><pre>
' VBScript

Function GetTolerance(Picture1, Picture2)
Dim WidthDim, HeightDim, DifPicture, ToleranceValue

ToleranceValue = 0
Set DifPicture = Picture1.Difference(Picture2, False, 0, True)
For WidthDim = 0 To DifPicture.Size.Width - 1
For HeightDim = 0 To DifPicture.Size.Height - 1
If DifPicture.Pixels(WidthDim, HeightDim) = vbRed Then
ToleranceValue = ToleranceValue + 1
End If
Next
Next
GetTolerance = ToleranceValue
End Function
</pre><hr />

I hope this helps.

4. ## Re: Pixel difference between two images?

To add to Alex's comments, and given your recent posts about DirectX, you may want to consider a slightly fuzzier image matching technique. Myself and Brent had a discussion about this a while back here. If you are comparing a lot of frames, a pixel by pixel comparison in VBscript will also be very slow. In your place, I'd tend to write this as an external routine in C or C++. VBScript and DirectX don't really have similar notions of 'speed' [img]/images/graemlins/wink.gif[/img]

5. ## Re: Pixel difference between two images?

Hi Alex, If you can please translate above VB script to Jscript it will be useful for me.

How fast will be the single comparison of two 1200x1068 sized image? Ca you give any time estimate on this?
(I will be doing lot of image comparison like this)

Thanks.

6. ## Re: Pixel difference between two images?

<font class="small">Code:</font><hr /><pre>
//JScript
Function GetTolerance(Picture1, Picture2)
{
var WidthDim, HeightDim, DifPicture, ToleranceValue;
ToleranceValue = 0
DifPicture = Picture1.Difference(Picture2, False, 0, True);
for (WidthDim = 0; WidthDim&lt;DifPicture.Size.Width; WidthDim++)
for (HeightDim = 0;HeightDim &lt; DifPicture.Size.Height; HeightDim++)
If (DifPicture.Pixels(WidthDim, HeightDim) == vbRed)
ToleranceValue = ToleranceValue + 1
}
</pre><hr />

The only thing I not sure of is the vbRed.

7. ## Re: Pixel difference between two images?

Eric,

We've analyzed this code sample and think it shows promise. I did have concerns regarding speed. How fast would you expect this to run on a 800x600 image on your average dual core system? &lt; 1 min? A few moments?

Our latest camera is 11 megapixels, and I am considering instead validating on an array of pixels instead of every pixel, say a 10x10 pixel array spread out across each image. Any thoughts on this? For what we are doing it should be unlikely that all 100 pixels will ever be different between any two frames. Any thoughts?

For jscript vbRed will not be available however Builtin.clRed should work just fine. We can always use an rgb converter or hex if we needed to do anything different.

8. ## Re: Pixel difference between two images?

We tested above code and found that it is too slow for the practical use as it compares pixel by pixel. It took us around 7 mins to compare two images of size 1024x768.

If anyone knows better solution for pixel comparison please post it here.

Thanks
Manas.

9. ## Re: Pixel difference between two images?

One thing you could try is a .NET class library and load it using the CLR Bridge and call it. (Or write a TC plug-in)

10. ## Re: Pixel difference between two images?

Eric,

Can you please elaborate on it?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.