Re: please help with ndvi calculation [message #52832] |
Thu, 01 March 2007 21:26  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
beardown911@gmail.com writes:
> I am new in idl programming, and have been trying to figure out to
> write a simple code to calculate ndvi.
>
> Here is what I've done, but gave weird value.
> ------------------------------------------------------
> pro ndvi
> image = read_tiff ('/rsi/idl62/training/data/image.tif')
> help, image
>
> sub = float(image[0,*,*]-image[1,*,*])
> sum = float(image[0,*,*]+image[1,*,*])
>
> ndvi_image = sub / sum
>
> write_tiff, '/rsi/idl62/training/data/ndvi_test.tif', ndvi_image
> end
> -------------------------------------------------------
> The image.tif have three bands(nir, red, green) 8 bit image.
> The resulting ndvi image is still integer and values are totally
> wrong.
> Could anybody help me to fix this?
Cast your image to float *before* you do the calculations.
You are casting the *result* to a float, but the damage
has already been done when you did the calculations in
BYTE or INTEGER math.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|