r - NDVI difference -
i have 2 ndvi images having values -1 1 min/max....i want subtract 2nd image 1st or vice-versa when doing giving me raster 0 value...which think should subtract 1 band other or 1 image another....kindly help me getting wrong.....here code using see change....
b3<-raster(stackim1,3) #band 3 of first input image b4<-raster(stackim1,4) #band 4 of first input image ndvi1<-(b4-b3)/(b4+b3) #calculating ndvi first image b3<-raster(stackim2,3) #band 3 of sec image b4<-raster(stackim2,4) #band 4 of sec image ndvi2<-(b4-b3)/(b4+b3) #calculating ndvi sec image ndvi <- ndvi1-ndvi2 #subtracting sec ndvi image first
thanks in advance
this how can create reproducible example:
generate data
library(raster) r <- raster(nc=10, nr=10) set.seed(2212013) stackim1 <- stack(lapply(1:5, function(x) setvalues(r, round(runif(ncell(r))* 255)))) stackim2 <- stack(lapply(1:5, function(x) setvalues(r, round(runif(ncell(r))* 255))))
and utilize illustrate problem
b3<-raster(stackim1,3) #band 3 of first input image b4<-raster(stackim1,4) #band 4 of first input image ndvi1<-(b4-b3)/(b4+b3) #calculating ndvi first image b3<-raster(stackim2,3) #band 3 of sec image b4<-raster(stackim2,4) #band 4 of sec image ndvi2<-(b4-b3)/(b4+b3) #calculating ndvi sec image ndvi <- ndvi1-ndvi2 #subtracting sec ndvi image first
but not see problem here.
> ndvi class : rasterlayer dimensions : 10, 10, 100 (nrow, ncol, ncell) resolution : 36, 18 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=wgs84 info source : in memory names : layer values : -1.461194, 1.590255 (min, max) >
r raster
No comments:
Post a Comment