I am planning to use R to read hyperspectral images and calculate hyperspectral indices. There seems to be scripts available online, but mostly for multispectral images. For instance, this code for NDVI uses only two bands:

VI <- function(img, k, i) {
          bk <- img[[k]]
          bi <- img[[i]]
          vi <- (bk - bi) / (bk + bi)

 #knowing the band numbers for k(5) and i(3), the NDVI is:

 ndvi <- VI(hyper_image, 5, 3)

My dilemma is: I use a hyperspectral image with 100 bands. The above code becomes inefficient because I want to use all 100 bands in the formula.

#if, for example, these are my 100 bands: k, i, j, n, m, o, p, .... 

#And just for the sake of illustration, this is a sample equation:

vi <- (bk + bi + bj + bn + bm + bo + bp + ....) / (bk + bi + bj + bn + bm + bo + bp + ....)


hyper_index <- VI(hyper_image, 5, 3, 6, 7, 8, 9, 1, ...)

#Obviously, doing this is excruciating!

Can someone point me to existing R code for this procedure?


1 Answer 1


You may consider using the R package hsdar as a starting point to carry out transformation of spectral response data as well calculation of vegetation indices. You will find additional information about this package in this article published in the Journal of Statistical Software. While the hyperSpec package might also be of use.

This tutorial provides useful information on working with hyperspectral data in R using the hdf5 format.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.