Page 1 of 1

Compare images

Posted: Thu Feb 28, 2013 7:09 pm
by spacebuddy
Hi All,

Is there anything in PB that allows you to compare two images to see if
they are identical?

:D

Re: Compare images

Posted: Thu Feb 28, 2013 7:13 pm
by J. Baker
If you use Point(), you can compare per pixel. You can even use Plot() to draw hot pink (or something like that) on the second image or even a third, to see the difference.

Re: Compare images

Posted: Thu Feb 28, 2013 7:42 pm
by wilbert
If you get the address of the pixel data, you could use CompareMemory.

Re: Compare images

Posted: Thu Feb 28, 2013 7:45 pm
by spacebuddy
J. Baker wrote:If you use Point(), you can compare per pixel. You can even use Plot() to draw hot pink (or something like that) on the second image or even a third, to see the difference.

I tried that, but it is to slow for me :cry:

Re: Compare images

Posted: Thu Feb 28, 2013 7:46 pm
by spacebuddy
wilbert wrote:If you get the address of the pixel data, you could use CompareMemory.

I am getting the image from the clipboard, so I am not sure how you can get the address?

Re: Compare images

Posted: Thu Feb 28, 2013 8:45 pm
by J. Baker
spacebuddy wrote:
J. Baker wrote:If you use Point(), you can compare per pixel. You can even use Plot() to draw hot pink (or something like that) on the second image or even a third, to see the difference.

I tried that, but it is to slow for me :cry:
It shouldn't be. Do all your comparing in the background. Not like where you can visually see it comparing in a window or something. Then when done comparing, then draw the result images so you can visually see it. ;)

Re: Compare images

Posted: Thu Feb 28, 2013 10:30 pm
by Fred
Another way is to use DrawingBuffer() and then compare lines by lines with CompareMemory().

Re: Compare images

Posted: Fri Mar 01, 2013 4:57 am
by spacebuddy
I am trying it a different way by trying to get the crc value of the image. This is the
code I am using which does not work :cry:

StartDrawing( ImageOutput( ImageHandle ) )
image_data = DrawingBuffer()
StopDrawing()
Length = MemoryStringLength(*image_data)
Result = CRC32Fingerprint(*image_data, Length)

Anyone tell me why this does not work. :D

Thanks all for the replies.

Re: Compare images

Posted: Fri Mar 01, 2013 8:11 am
by infratec
Hi,

Maybe because you forgot an *
But still than, you can not use MemoryStringLength() since a picture contains 0
And MemorySize() works only with AllocateMemory()

Maybe this works;

Code: Select all

EnableExplicit

Define ImageHandle.i, *Buffer, Pitch.i, Length.i, Result.l

CreateImage(ImageHandle, 300, 200)

StartDrawing(ImageOutput(ImageHandle))
*Buffer = DrawingBuffer()
Pitch = DrawingBufferPitch()
Length = Pitch * ImageHeight(ImageHandle)
Result = CRC32Fingerprint(*Buffer, Length)
StopDrawing()

Debug Hex(Result, #PB_Long)
Bernd

Re: Compare images

Posted: Fri Mar 01, 2013 10:37 am
by Fred
The DrawingBuffer() is invalidated on StopDrawing, so you can't store the pointer and use it after StopDrawing().

Re: Compare images

Posted: Fri Mar 01, 2013 10:51 am
by infratec
Thanks Fred,

I corrected the listing above.

Bernd

Re: Compare images

Posted: Fri Mar 01, 2013 6:24 pm
by spacebuddy
Thank you all, everything working now :D