我有一张图片,它由每个像素中的坐标(x,y)和一些强度参数组成.它的形状不规则.它还可能有一些洞.这是我拥有的矩阵的一个例子:
set.seed(20)
test <- expand.grid(1:25, 1:50)
test$Int <- rnorm(nrow(test), 7, 1)
edge_rows <- which(test$Var1 %in% c(1, 25) | test$Var2 %in% c(1, 50))
rows_to_remove <- sample(edge_rows, 50)
test <- test[-rows_to_remove, ]
edge_rows <- which(test$Var1 %in% c(2, 24) | test$Var2 %in% c(2, 49))
rows_to_remove <- sample(edge_rows, 25)
test <- test[-rows_to_remove, ]
rows_to_remove <- sample(edge_rows, 75)
test <- test[-sample(nrow(test), 50), ]
ggplot(test) +
geom_tile(aes(Var1, Var2, fill = Int))
没有(x,y,Int)注释且被其他像素包围的像素被认为是洞,我正在寻找仅针对边缘的索引.
提前感谢您