Turning imageData into alphaData (quickly)?
Wilhelm Sanke
sanke at hrz.uni-kassel.de
Mon Mar 13 11:56:52 EST 2006
On Mon Mar 13, 2006, Ian Wood revlist at azurevision.co.uk wrote:
> (snip)
> A handler that goes through each RGB pixel and reduce it to a
> grayscale value for use as alphaData was pretty easy, but for a
> 200x200px image that's 40,000 repeats, and takes minutes on a G5.
>
> on maskStuff
> put the seconds into tStart
> put "" into tMaskData
> put the imageData of img "mask" into tImgData
> put number of chars of tImgData / 4 & return into fld "status"
> lock screen
> repeat with x = 1 to ((number of chars of tImgData) / 4)
> if the mouse is down then exit to top
> put charToNum(char (x*4)-2 of tImgData) into tR
> put charToNum(char (x*4)-1 of tImgData) into tG
> put charToNum(char (x*4) of tImgData) into tB
> put the round of ((tR + tG + tB)/3) into tM
> put numToChar(tM) after tMaskData
> --put tM & return after fld "status"
> end repeat
> (snip)
> Any ideas for a faster way? Cross-platform command-line tools?
>
> Ian Wood
> Panoramic photography, from web to billboard, sunrise to moonrise
> http://www.landmarksofbritain.co.uk
Hi Ian,
I modified your script to the solution below, i.e. I took the script of
my "gray-scale" button of my ImageData Toolkit and adapted it to your needs.
The script is for a 640 X 480 image, meaning that more than about one
million of chars have to be processed (640 * 480 * 3)
Running the script takes *one* second on my Windows XP computer (2 GHz):
on mouseUp
set the cursor to watch
put the milliseconds into Start
put the imageData of image 2 into iData
put empty into tmaskdata
put 2560 into re # i.e. 640 * 4
repeat with i = 0 to 479
repeat with j = 0 to 639
put chartonum(char (i*re + (j*4+2)) of idata) into tC1
put chartonum(char (i*re + (j*4+3)) of idata) into tC2
put chartonum(char (i*re + (j*4+4)) of idata) into tC3
put the round of ((tc1 + tc2 + tc3)/3) into tM
put numToChar(tM) after tMaskData
end repeat
end repeat
put the milliseconds - Start into fld "test"
end mouseUp
Best regards,
Wilhelm Sanke
<http://www.sanke.org/MetaMedia>
<http://www.sanke.org/ImageDataArt>
More information about the use-livecode
mailing list