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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: please help with ndvi calculation [message #52832] Thu, 01 March 2007 21:26
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.")
Re: please help with ndvi calculation [message #52834 is a reply to message #52832] Thu, 01 March 2007 21:23 Go to previous message
Pierre V. is currently offline  Pierre V.
Messages: 13
Registered: December 2006
Junior Member
Phil,

My guess is that the function write_tiff is internally converting your
NDVI to type byte before writing it to a file. You can either scale
your data to properly fit into bytes using something like:

ndvi_byte = bytscl(ndvi_image, min = -1, max = 1).

Or you can try using the /float keyword to write_tiff to force it to
write out your data as floats.

-Pierre
  Switch to threaded view of this topic Create a new topic Submit Reply
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 13:38:52 PDT 2025

Total time taken to generate the page: 0.00784 seconds