meowbits Posted April 2, 2010 Posted April 2, 2010 Is there a function for reading images into 2d arrays? If there is, mind pointing me towards it? Thanks.
BrettF Posted April 3, 2010 Posted April 3, 2010 Not that I can think of. But I'm pretty sure there is a function to read a specific pixel of an image... Combine that with a loop of the X and Y components of an image, and you've got your image -> 2D array. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Malkey Posted April 3, 2010 Posted April 3, 2010 This is one way of getting the colour pixels in an image file into an array. expandcollapse popup#include <Array.au3> #include <GDIPlus.au3> Local $filename, $begin, $aArr, $time Local $filename = FileOpenDialog("Select image", @DesktopCommonDir, "All images (*.jpg;*.png;*.gif;*.bmp;)", 1) If $filename = "" Then Exit ShellExecute($filename) $begin = TimerInit() _FileImageToArray($filename, $aArr) $time = Round(TimerDiff($begin) / 1000, 3) ;_ArrayDisplay($aArr) MsgBox(0, "Check bottom-right element in 2D array", "Pixel colour at coordinates (" & _ UBound($aArr, 1) & ", " & UBound($aArr, 2) & ") of image = 0x" & _ $aArr[UBound($aArr, 1) - 1][UBound($aArr, 2) - 1] & @CRLF & @CRLF & _ "Time taken = " & $time & " secs") Func _FileImageToArray($sFileName, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $iIW, $iIH, $hImage Local $v_Buffer, $width, $height _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sFileName) $iIW = _GDIPlus_ImageGetWidth($hImage) $iIH = _GDIPlus_ImageGetHeight($hImage) ProgressOn("Progress Bar", "Filling a " & $iIW & " x " & $iIH & " size array.", "0 percent") $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iIW, $iIH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Dim $aArray[$height][$width] For $j = 0 To $iIH - 1 For $i = 0 To $iIW - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) $aArray[$j][$i] = Hex(DllStructGetData($v_Buffer, 1), 6) Next ProgressSet(Int(100 * $j / ($iIH)), Int(100 * $j / ($iIH)) & " percent") Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) ProgressOff() _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return EndFunc ;==>_FileImageToArray Gianni 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now