Fast Algorithm to Determine Average Brightness of an Image
hh
hh at hyperhh.de
Tue Sep 20 16:14:07 EDT 2016
> So is there a fast, efficient way to analyze a 1200 X 800 px
> image to get this average brightness value.
You could try the following function. It is "dirty" (the definition
of 'brightness' is also unsharp!), but it is very fast.
local ii="tmp-1.414214"
-- uses the average color intensity of the pixel
-- resulting from scaling down to a 1x1 image
function avgBrightness theImage
lock screen; lock messages
if there is no img ii then create img ii
set resizeQuality of img ii to "best"
set width of img ii to the width of img 1
set height of img ii to the height of img 1
set imagedata of img ii to the imagedata of theImage
set width of img ii to 1
set height of img ii to 1
put the imagedata of img ii into iData
delete img ii
return avg (byteToNum(byte 2 of iData), \
byteToNum(byte 3 of iData), \
byteToNum(byte 4 of iData))
unlock screen; unlock messages
end avgBrightness
More information about the use-livecode
mailing list