Solved

# compare two images pixel by pixel

Posted on 2005-03-26
Medium Priority
290 Views
how is it possible to compare two images and tell in what areas they're different..?
0
Question by:davidlars99
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2

LVL 12

Expert Comment

ID: 13644177
Sorry about the delay in helping with this...

Just wanted to check really... you want to check every single pixel... or possibly a set area?

Also, is this like a one off comparison of two images... or will it be continuous checking of a new Image... and the last image... like if you were captuing a webcam image, and wanted to monitor for a change (especially in this case, you may want to limit the number of pixels)
0

LVL 13

Author Comment

ID: 13644812
thanks Steve, you can give me all you can and I'll start researching by myself then, just put me into right direction...  :)
0

LVL 12

Accepted Solution

S-Twilley earned 2000 total points
ID: 13644863
Well this is the less efficient way (I've since seen a better way but have not implemented it).

' BitmapA and BitmapB are bitmap objects...

Dim different As Boolean = False
If BitmapA.Size.Equals(BitmapB.Size) Then
Dim xcoord, ycoord As Single
Dim pixelA, pixelB As Color

For xcoord = 0 To BitmapA.Width - 1
For ycoord = 0 To BitmapA.Height - 1
pixelA = BitmapA.GetPixel(xcoord, ycoord)
pixelB = BitmapB.GetPixel(xcoord, ycoord)

If Not pixelA.Equals(pixelB) Then
different = True
Exit For
End If
Next
If different Then Exit For
Next
Else
different = True
'Different sizes
End If

If different Then
MsgBox("The bitmaps are different")
Else
MsgBox("The bitmaps are the same")
End If

==================

I'll try and work on the better version that doesn't use GetPixel now... but there's something for you to work with
0

LVL 12

Expert Comment

ID: 13644874
just a note:   this is assuming that you're not using a fixed pallete on the bitmaps, you should probably test for differing pallettes as well... but i was assuming that they're in true color
0

LVL 12

Expert Comment

ID: 13645002
well   using LockBits is supposed  to be better than using GetPixel

http://www.bobpowell.net/lockingbits.htm

but I'm not sure about the Marshal.WriteByte part...   it's meant to be more efficient, but if you limit the number of comparisons, GetPixel shouldn't be too much of a resource hog
0

LVL 13

Author Comment

ID: 13775722
thanks Steve, I liked it
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month13 days, left to enroll