[Image-SIG] Raster Calculation

Fredrik Lundh fredrik at pythonware.com
Wed Apr 1 22:03:23 CEST 2009


2009/4/1 santosh panda <santoshh19 at yahoo.co.in>:
> Dear List members,
>
> I am a beginner in Python programming, I want to write a python script which
> would take 1 band .tiff raster image as input, then calculate the
> reflectance value for each pixel using the following equation
> [refl] = (pi * ((((lmax - lmin) / 255) * [filename])
> + lmin) * d^2 ) / (esun * COS((90 - elevation) * .017453293))
> and write the output to a raster file.

You could use PIL's ImageMath module:

>>> from PIL import Image, ImageMath, math
>>> im = Image.open("input.tif")
>>> out = ImageMath.eval("... expr ...", dict(im=im, lmax=..., pi=math.pi))
>>> out.save("output.tif")

(see the handbook for details)

or, alternatively, especially if you want to do more extensive
calculations, numpy.

Are elevation, esun etc constant for the whole image, btw?

</F>


More information about the Image-SIG mailing list