【问题标题】:Problem on Normalized Difference Vegetation Index (NDVI) index calculation on image (R)图像(R)上的归一化差异植被指数(NDVI)指数计算问题
【发布时间】:2021-10-15 11:26:15
【问题描述】:

在获得一个 NDVI 指数(在以下代码中称为 S)后,我想计算值高于图像限制(以下代码中为 0.02)的像素数。我尝试了很多方法,但它不起作用(我已经检查过我的值是否低于 0.02)。使用的图片:1https://i.stack.imgur.com/8HCuZ.jpg

## load package
library(raster)
library(oceanmap)
#load satellite image of a park
f <- stack(list.files(path='C:/Users/Desktop/Segmentation', full.names=TRUE))
###################################################
###################################################
b <- brick(f)
###################################################
# obtain the R, G and B layer of the initial image raster
R <- b[[1]]
G <- b[[2]]
B <- b[[3]]
###################################################
#color vegetation indices
S <- (G-B)/(R+G+B)
> class(S)
[1] "RasterLayer"
attr(,"package")
[1] "raster"
> SumS0 <- as.numeric(sum(S[] < 0.02))
> SumS0
[1] NA
> S1 <- as.matrix(S)
> SumS1 <- as.numeric(sum(S1[] < 0.02))
> class(S1)
[1] "matrix" "array" 
> SumS1
[1] NA
> S2 <- raster2matrix(S)
> SumS2 <- as.numeric(sum(S2[] < 0.02))
> SumS2
[1] NA
> S3 <- as.data.frame(S)
> SumS3 <- as.numeric(sum(S3[] < 0.02))
> SumS3
[1] NA

对于随机矩阵,它可以工作:

M1<-matrix(rnorm(36),nrow=6)
SumM1 <- as.numeric(sum(M1[] < 0.02))
SumM1
[1] 15

【问题讨论】:

  • 可能是sum(as.numeric(S) &lt; 0.02, na.rm = TRUE)
  • 谢谢,它使用 sum(S[]

标签: r image-processing matrix raster


【解决方案1】:

您计算 NDVI 的算法似乎是正确的,所以我认为您的实现有问题。如果我使用 ImageMagick 运行它,我会得到我所期望的:

我在终端中使用了这个:

magick 8HCuZ.jpg -fx "((g-b)/(r+g+b))>0.02 ? 1 : 0" result.png

顺便说一句,你的照片质量 (70) 相当低,并且会导致丑陋的伪像。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2021-02-17
    • 1970-01-01
    • 2016-08-21
    相关资源
    最近更新 更多