0

I am super new to IDL, level 0. I was wondering if anyone can help me calculate NDVI for BIL or BIP file. I have one file. I understand the concept of NDVI, the inverse relationship between NIR and R. I am just not sure how to put that in a code.

Also, I know that NDVI is floating point, However, I need to save the final NDVI product in bytes.

Can anyone help? Thanks.

veda905
  • 782
  • 2
  • 12
  • 32
Chyrel
  • 1
  • 1

1 Answers1

0

What format are the data files in? It's pretty easy to use one of the READ_XXXX routines if it is in one of the image formats, so I will do the harder case that it is just a binary file. I assume you know the size (n_bands, n_samples, n_lines), interleave (BIL or BIP), and data type (float below) of the image as well as the indices of the bands for NIR (nir_band) and R (r_band).

im = fltarr(n_samples, n_bands, n_lines)  ; this is BIL
; use im = fltarr(n_bands, n_samples, n_lines) for BIP

; nir_band is an index, 0..n_bands - 1, representing near infrared light
; r_band is an index, 0..n_bands representing the visible light

nir = float(im[*, nir_band, *])
r = float(im[*, r_band, *])
ndvi = (nir - r) / (nir + r)

; you might want to use the MIN and MAX if you want to scale in a certain
; manner
byte_ndvi = bytscl(ndvi)
mgalloy
  • 2,356
  • 1
  • 12
  • 10