compare two images pixel by pixel

how is it possible to compare two images and tell in what areas they're different..?
LVL 13
davidlars99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

S-TwilleyCommented:
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
davidlars99Author Commented:
thanks Steve, you can give me all you can and I'll start researching by myself then, just put me into right direction...  :)
0
S-TwilleyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

S-TwilleyCommented:
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
S-TwilleyCommented:
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
davidlars99Author Commented:
thanks Steve, I liked it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.