Compare images

Mac OSX specific forum
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Compare images

Post by spacebuddy »

Hi All,

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

:D
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Compare images

Post 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.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Compare images

Post by wilbert »

If you get the address of the pixel data, you could use CompareMemory.
Windows (x64)
Raspberry Pi OS (Arm64)
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: Compare images

Post 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:
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: Compare images

Post 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?
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Compare images

Post 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. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Fred
Administrator
Administrator
Posts: 18499
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Compare images

Post by Fred »

Another way is to use DrawingBuffer() and then compare lines by lines with CompareMemory().
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: Compare images

Post 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.
infratec
Always Here
Always Here
Posts: 7794
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Compare images

Post 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
Last edited by infratec on Fri Mar 01, 2013 10:50 am, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 18499
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Compare images

Post by Fred »

The DrawingBuffer() is invalidated on StopDrawing, so you can't store the pointer and use it after StopDrawing().
infratec
Always Here
Always Here
Posts: 7794
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Compare images

Post by infratec »

Thanks Fred,

I corrected the listing above.

Bernd
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: Compare images

Post by spacebuddy »

Thank you all, everything working now :D
Post Reply