Link to home
Start Free TrialLog in
Avatar of Lukie Luke
Lukie Luke

asked on

[VB6] Compare two images and show percentage that one matches the other ?

I use the GetDIBits() API function to compare two images to tell if they're the same or different much quicker than using GetPixel or other methods. But is there any way to show percentage that one matches the other ? Here is the project
CompareImages.zip
Avatar of aikimark
aikimark
Flag of United States of America image

The correct approach for best performance is to populate two arrays as efficiently as possible and then compare the pixel locations.  Count the number of times the pixel values are different and divide by the total number of pixels (=rows*columns)
Avatar of Lukie Luke
Lukie Luke

ASKER

Can you specify the code ? Thank you in advance :)
If you are using the API function, you already have the arrays populated.  Nest two For...Next loops, one for the row value and one for the column value.
Example:
For lngRow=0 to ubound(dibarray,1)
   For lngCol=0 to ubound(dibarray,2)
   Next
Next

Open in new window

Sorry I don't want to bother you but please read, edit the project and upload it again. My main problem is to show the percentage between two images. I don't really understand your code.
@Lukie Luke

please read, edit the project and upload it again
Is this your program?
Do you know how to program?
I'm new to VB. I found it from vbforum
Do you know how to program in any language?
@aikimark Yes, I know a bit of programing in Visual Basic 6.0
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, sir
The .bas file in that zip is represented here.

There is a nested loop at the end of that VB code, "Private Function ComparePixels() As Boolean "

If you create a similar function with a nested loop, counting when pixels are true, or false, or both, then you have the basis for a percentage calculation. (nb: if you have the total size to start with then you don't need both but you could do it that way.)

Note the existing function has an "Exit For" escape, so it does not compare all pixels if a difference is found (so it is just determining "different" or "not-different").

ps: I haven't touched VB in a million years (or thereabouts) so I'm not offering more than this
Thank you sir for the advise :)