comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: please help with ndvi calculation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: please help with ndvi calculation [message #52832] Thu, 01 March 2007 21:26 Go to previous message
David Fanning is currently offline  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.")
[Message index]
 
Read Message
Read Message
Previous Topic: please help with ndvi calculation
Next Topic: Re: How can I multi-plot in IDL with the coordinates set by myself?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:36:03 PDT 2025

Total time taken to generate the page: 0.00518 seconds