【问题标题】:How to get the color coded plotted areas in images using R?如何使用 R 在图像中获取颜色编码的绘图区域?
【发布时间】:2016-03-29 18:45:19
【问题描述】:

嗨,世界 R 专家, 假设我有一个生成强度图的点模式,并且该图在像素化图像的 3 个区域中进行了颜色编码......我怎样才能获得颜色编码区域?

这是一个使用 spatstat 的示例:

library(spatstat)
japanesepines
Z<-density(japanesepines); plot(dens) # ---> I create a density map
b <- quantile(Z, probs = (0:3)/3) # ---> I "reduce it" to 3 color-ceded zones
Zcut <- cut(Z, breaks = b, labels = 1:3); plot(Zcut)
class(Zcut) # ---> and Zcut is my resultant image ("im")

提前谢谢你 囊

【问题讨论】:

  • 我其实是想计算每种颜色的像素面积

标签: r pixel area spatstat


【解决方案1】:

在您的具体示例中,计算面积非常容易,因为您使用quantile 剪切图像:这有效地将图像划分为大小相等的区域,因此应该有三个大小为 1/3 的区域,因为window 是一个单位正方形。一般来说,要从因子值图像中计算面积,您可以使用 as.tesstile.areas(继续您的示例):

Ztess <- as.tess(Zcut)
tile.areas(Ztess)

在这种情况下,面积为 0.333313,这一定是由于离散化。

【讨论】:

    【解决方案2】:

    我不完全确定您想要的是什么,但您可以使用 table() 函数计算每种颜色的像素数。

    table(Zcut[[1]])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      相关资源
      最近更新 更多