Programmatically determine the average greyscale

Sannyasin Brahmanathaswami brahma at hindu.org
Thu Feb 18 21:44:14 EST 2016


Thanks that could be useful... BTW where to you store this kind of snippet

We need an online repository for scripts like this... something simpler than GIT,

Actually determining the luminance algorithm is pretty straight forward... even easier than this formula.. but how do you get the color a specific pixel in an image?


BR


On February 18, 2016 at 4:27:29 PM, J. Landman Gay (jacque at hyperactivesw.com<mailto:jacque at hyperactivesw.com>) wrote:

I'm not sure about getting an average, but someone posted the following
handler here a while ago. I'm sorry I can't give credit, I should have
saved that.

Determine whether to show white or black text against a colored background:

function calcLuminance pRGB
-- wikipedia: Y = 0.2126 R + 0.7152 G + 0.0722 B
put item 1 of pRGB * 0.2126 into tR
put item 2 of pRGB * 0.7152 into tG
put item 3 of pRGB * 0.0722 into tB
if sum(tR,tG,tB) > 125 then return "black"
else return "white"
end calcLuminance


More information about the use-livecode mailing list