[Image-SIG] Raster Calculation: Script Error

santosh panda santoshh19 at yahoo.co.in
Fri Apr 3 04:59:42 CEST 2009


Dear List Members,

I am using Landsat single band image as input and I want to apply the equation shown below in the script and write the output to a new raster file.

1. The below pasted script works fine without 'cos' term but it fails with 'cos' term even if I imported python math module. Should I import any other module so that the script will recognize 'cos' term?

2. I want my output data to be in same projection and pixel size as my input data. What command do I have to use to maintain the projection details and pixel size?

3. My input data is 8 bit and I want my output data also in 8 bit. How can I maintain the data mode?

script:
from PIL import Image, ImageMath
import os, math
os.curdir = 'C:/temp'
im = Image.open("testraster.tif")
out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37)
out.save("outRaster.tif")

print 'All done...'

Traceback (most recent call last):
  File "C:\temp\reflectance.py", line 7, in <module>
    out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37)
  File "C:\Python25\Lib\site-packages\PIL\ImageMath.py", line 203, in eval
    out =__builtin__.eval(expression, args)
  File "<string>", line 1, in <module>
NameError: name 'cos' is not defined
 
I looked in the Imaginbook and its tutorial section, but didn't find the exact answer to my questions. I would appreciate any suggestion or help to solve my problem.

Thanks in advance.

Santosh 
 


      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090403/32a0e133/attachment.htm>


More information about the Image-SIG mailing list