Jump to content

Matching pixel\images


 Share

Recommended Posts

Hey you guys. im looking for a function that matches pixel if its the same on 2 diffrent regions. Like pixelchecksum but if the region A is allmost like regin B then it returns % how big the difference is.

Example1:

Region a:

----------

----------

----------

Region b:

----------

----|-----

----------

return = 99% since 1 - is only changed from Region A to Region B.

Example2:

Region a:

----------

----------

----------

Region b:

||||||||||

||||||||||

||||||||||

return = 0% nothing looks the same

please tell me if this is NOT understandable.

Link to comment
Share on other sites

  • Moderators

Hey you guys. im looking for a function that matches pixel if its the same on 2 diffrent regions. Like pixelchecksum but if the region A is allmost like regin B then it returns % how big the difference is.

Example1:

Region a:

----------

----------

----------

Region b:

----------

----|-----

----------

return = 99% since 1 - is only changed from Region A to Region B.

Example2:

Region a:

----------

----------

----------

Region b:

||||||||||

||||||||||

||||||||||

return = 0% nothing looks the same

please tell me if this is NOT understandable.

Some one wrote something like that a while ago, but it was quite inefficient. It used PixelGetColor, then it looped 1 last time (total of 2 - 2 level loops and a 3rd loop to compare the findings).

You'd have to look up something like GetDIBits or GetDIBSection to even come close to something in speed to be worth wild. But even then, imagine searching a large area with it: 1600x1200 or something, look at all the loops it would still have to go through to compare, I wouldn't expect that to be even remotely speed friendly in autoit.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Some one wrote something like that a while ago, but it was quite inefficient. It used PixelGetColor, then it looped 1 last time (total of 2 - 2 level loops and a 3rd loop to compare the findings).

You'd have to look up something like GetDIBits or GetDIBSection to even come close to something in speed to be worth wild. But even then, imagine searching a large area with it: 1600x1200 or something, look at all the loops it would still have to go through to compare, I wouldn't expect that to be even remotely speed friendly in autoit.

Do you remember the name of the post :P? i know auto-it aint that fast with stuff but wanna try anway.

You can do this with ImageMagick

http://www.imagemagick.org/script/compare.php

Thnx but i wanna stay in auto-it

Link to comment
Share on other sites

  • Moderators

Do you remember the name of the post :P? i know auto-it aint that fast with stuff but wanna try anway.

No, it was some time ago. But the concept isn't that difficult.

2 loops

For x = xstart to xend

For y = ystart to yend

+ an array to hold values for each loop

Next

Next

Repeat above for 2nd region

then a 3rd loop to compare the two arrays.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No, it was some time ago. But the concept isn't that difficult.

2 loops

For x = xstart to xend

For y = ystart to yend

+ an array to hold values for each loop

Next

Next

Repeat above for 2nd region

then a 3rd loop to compare the two arrays.

ow with a big pic this will make auto-it work hard ><. well thanks i will try some :P
Link to comment
Share on other sites

  • Moderators

ow with a big pic this will make auto-it work hard ><. well thanks i will try some :P

Well, that's exactly what I said in my first post.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

How do you want to handle different sized regions

Are you comparing regions on screen, regions in different files, or regions from one file?

Edited by weaponx
Link to comment
Share on other sites

Here is a version using straight GDI+, I tested it on a 100x100 image but _GDIPlus_BitmapLockBits chokes on 1680x1050 files:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

    ; Initialize GDI+ library
_GDIPlus_Startup ()


;Get handle to an Image object
$pBitmap1 = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\before.bmp")

;Get handle to an Image object
$pBitmap2 = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\after.bmp")


;Get $tagGDIPBITMAPDATA structure
$BitmapData1 = _GDIPlus_BitmapLockBits($pBitmap1, 0, 0, _GDIPlus_ImageGetHeight($pBitmap1), _GDIPlus_ImageGetWidth($pBitmap1), $GDIP_ILMWRITE, $GDIP_PXF32RGB)
If @ERROR Then MsgBox(0,"","Error locking region for writing")

;Get $tagGDIPBITMAPDATA structure
$BitmapData2= _GDIPlus_BitmapLockBits($pBitmap2, 0, 0, _GDIPlus_ImageGetHeight($pBitmap2), _GDIPlus_ImageGetWidth($pBitmap2), $GDIP_ILMWRITE, $GDIP_PXF32RGB)
If @ERROR Then MsgBox(0,"","Error locking region for writing")

;Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
$Stride1 = DllStructGetData($BitmapData1, "Stride")
ConsoleWrite("Bitmap Stride1: " & $Stride1 & @CRLF)

;Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
$Stride2 = DllStructGetData($BitmapData2, "Stride")
ConsoleWrite("Bitmap Stride2: " & $Stride2 & @CRLF)

;Image width - Number of pixels in one scan line of the bitmap.
$Width1 = DllStructGetData($BitmapData1, "Width")
ConsoleWrite("Bitmap Width1: " & $Width1 & @CRLF)

;Image width - Number of pixels in one scan line of the bitmap.
$Width2 = DllStructGetData($BitmapData2, "Width")
ConsoleWrite("Bitmap Width2: " & $Width2 & @CRLF)

;Image height - Number of scan lines in the bitmap.
$Height1 = DllStructGetData($BitmapData1, "Height")
ConsoleWrite("Bitmap Height1: " & $Height1 & @CRLF)

;Image height - Number of scan lines in the bitmap.
$Height2 = DllStructGetData($BitmapData2, "Height")
ConsoleWrite("Bitmap Height2: " & $Height2 & @CRLF)

;Pixel format - Integer that specifies the pixel format of the bitmap
$PixelFormat1 = DllStructGetData($BitmapData1, "PixelFormat")
ConsoleWrite("Bitmap PixelFormat1: " & $PixelFormat1 & @CRLF)

;Pixel format - Integer that specifies the pixel format of the bitmap
$PixelFormat2 = DllStructGetData($BitmapData2, "PixelFormat")
ConsoleWrite("Bitmap PixelFormat2: " & $PixelFormat2 & @CRLF)

;Scan0 - Pointer to the first (index 0) scan line of the bitmap.
$Scan01 = DllStructGetData($BitmapData1, "Scan0")
ConsoleWrite("Bitmap Scan01: " & $Scan01 & @CRLF)

;Scan0 - Pointer to the first (index 0) scan line of the bitmap.
$Scan02 = DllStructGetData($BitmapData2, "Scan0")
ConsoleWrite("Bitmap Scan02: " & $Scan02 & @CRLF)

$TotalPixels = $Width1 * $Height1
$RemainingPixels = $TotalPixels

For $row = 0 To $Height1 - 1
    For $col = 0 To $Width1 - 1
        $pixel1 = DllStructCreate("dword", $Scan01 + $row * $Stride1 + $col*4)    
        $color1 = Hex(DllStructGetData($pixel1, 1))
        
        $pixel2 = DllStructCreate("dword", $Scan02 + $row * $Stride2 + $col*4)    
        $color2 = Hex(DllStructGetData($pixel2, 1))
        
        If $color1 <> $color2 Then $RemainingPixels -= 1
        
        ;ConsoleWrite($color1 & ", " & $color2 & @CRLF)
    Next
    ;ConsoleWrite("-------" & @CRLF)
Next

$Difference = $RemainingPixels / $TotalPixels

ConsoleWrite("$TotalPixels: " & $TotalPixels & @CRLF)
ConsoleWrite("$RemainingPixels: " & $RemainingPixels & @CRLF)

MsgBox(0,"Percent difference", Round($Difference,2) * 100 & "%")

;Unlock region previously locked for writing
_GDIPlus_BitmapUnlockBits($pBitmap1, $BitmapData1)
_GDIPlus_BitmapUnlockBits($pBitmap2, $BitmapData2)

_GDIPlus_ImageDispose ($pBitmap1)
_GDIPlus_ImageDispose ($pBitmap1)

_WinAPI_DeleteObject ($pBitmap1)
_WinAPI_DeleteObject ($pBitmap2)

_GDIPlus_Shutdown()
Edited by weaponx
Link to comment
Share on other sites

How do you want to handle different sized regions

Are you comparing regions on screen, regions in different files, or regions from one file?

oh lol big sry! its pictures its about! Edited by tarre
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...