【问题标题】:Measure "ink" of a plot测量情节的“墨水”
【发布时间】:2014-01-31 03:41:42
【问题描述】:

我正在阅读 Tufte 的 data-ink ratio,我想知道是否可以测量情节使用的“墨水”量?

如果在 R 中无法使用其他工具,例如 GIMP 或 imagemagick?

【问题讨论】:

  • 我想复杂性在于解决方案是否应该自动确定哪些“墨水”对应于数据,哪些不对应。是不是就这么简单:“背景‘墨’不是数据,剩下的是?”
  • 不完全是。我不是要测量数据墨水比,而是要测量绘图的墨水量(不知何故与分辨率无关)。如果您知道绘制相同信息的 2 个绘图的“墨水”(因此“数据墨水”相同),您可以自己推导出数据墨水比率。
  • 如果您对两个图进行光栅化(参见raster 包),则可以测量“非白”点的数量。这会让你接近,特别是如果两个图在标签、轴、图例中具有相同数量的“背景”墨水......
  • 参见:http://stackoverflow.com/a/16788397/1412059

标签: r image plot visualization gimp


【解决方案1】:

我建议使用grid.cap() 将图形设备的内容转换为光栅,然后计算非白色像素(又称“墨水”)的比例是一件简单的事情。在下面的示例中,为了将计算重点放在绘图区域中的墨水上,我设置了par(mar=c(0,0,0,0)),但如果您还想检查轴、刻度、轴标签、标题中的墨水量,可以删除该行等。

library(grid)

## Plot to R's default graphical device
opar <- par(mar=c(0,0,0,0))
plot(rnorm(1e4), rnorm(1e4), pch=16) 

## Capture contents of the graphics device as a raster (bitmap) image
p <- grid.cap()

## Compute the proportion of pixels that are not white (i.e. are inked in)
sum(p!="white")/length(p)
# [1] 0.2414888

## Restore pre-existing graphical parameters
par(opar)                    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 2013-02-19
    • 1970-01-01
    • 2017-04-08
    • 2021-12-31
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    相关资源
    最近更新 更多