[Image-SIG] PIL 1.1.6 (ImageMath)

Douglas Bagnall douglas at paradise.net.nz
Wed May 25 04:36:49 CEST 2005


Andrew Chamberlain wrote:
>  The reason I ask is because I'm trying to calculate a
> ratio image between two bands in an RGB image, and was hoping the 
> ImageMath module in 1.1.5 might be able to help.

If speed does not matter much, something like this should work:

im = Image.open('some rgb image')
im2 = Image.new('L', im.size)
SCALE = 128

ratios = [min(int(SCALE * r / (g + 0.01)), 255)
           for r, g, b in im.getdata()]

im2.putdata(ratios)
im2.save('/tmp/ratio.png')



douglas



More information about the Image-SIG mailing list