0

我有两个 ndvi 图像,其最小值/最大值为 -1 到 1....我想从第一个图像中减去第二个图像,反之亦然,但是当我这样做时,它给了我值为 0 的光栅...我认为它应该是这样的,因为我们从另一个中减去一个波段或从另一个图像中减去一个图像......请帮助我哪里出错......这是我用来查看变化的代码...... .

    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 for first image

    b3<-raster(stackIm2,3) #band 3 of second image
    b4<-raster(stackIm2,4) #band 4 of second image
    ndvi2<-(b4-b3)/(b4+b3) #calculating NDVI for second image

    ndvi <- ndvi1-ndvi2  #subtracting second ndvi image from first

提前致谢

4

1 回答 1

2

这是制作可重现示例的方法:

生成一些数据

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))))

然后用它来说明问题

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 for first image

b3<-raster(stackIm2,3) #band 3 of second image
b4<-raster(stackIm2,4) #band 4 of second image
ndvi2<-(b4-b3)/(b4+b3) #calculating NDVI for second image

ndvi <- ndvi1-ndvi2  #subtracting second ndvi image from first

但我在这里没有看到问题。

> 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 
data source : in memory
names       : layer 
values      : -1.461194, 1.590255  (min, max)

> 
于 2013-02-22T01:45:55.573 回答