readPNG功能的结果是什么?

时间:2015-07-09 21:29:48

标签: r png

我不认为我理解函数readPNG。在帮助中,我们可以找到这段代码

img <- readPNG(system.file("img", "Rlogo.png", package="png"))

img是数字矢量num [1:76 1:100 1:4](但它以四个矩阵的形式显示)

当我读取另一个PNG文件(25 x 25,逻辑[仅黑色或白色像素])时,我得到了矢量num [1:25 1:25 1:3]。看起来这三个逻辑矩阵是相同的。能否请您解释一下readPNG函数的确切结果是什么?为什么一旦它被显示为4个矩阵,一次为三个?

1 个答案:

答案 0 :(得分:1)

虽然我承认很多R手册页都是钝的,但这个页面非常好。

Value

If native is FALSE then an array of the dimensions height x width x
channels. If there is only one channel the result is a matrix. The
values are reals between 0 and 1. If native is TRUE then an object of
the class nativeRaster is returned instead. The latter cannot be
easily computed on but is the most efficient way to draw using
rasterImage.

Most common files decompress into RGB (3 channels), RGBA (4 channels),
Grayscale (1 channel) or GA (2 channels). Note that G and GA images
cannot be directly used in rasterImage unless native is set to TRUE
because rasterImage requires RGB or RGBA format (nativeRaster is
always 8-bit RGBA).

As of png 0.1-2 files with 16-bit channels are converted in full
resolution to the array format, but the nativeRaster format only
supports 8-bit and therefore a truncation is performed (eight least
significant bits are dropped) with a warning if native is TRUE.