2015-07-09 176 views
-1

我不认为我理解功能readPNG。在帮助我们可以发现这一段代码readPNG函数的结果是什么?

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

img是numieric向量NUM [1:76 1:100 1:4](但它是在四个矩阵形式dispalyed)

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

+1

你没有提到该函数来自包** png **。您是否阅读过'readPNG'文档的Value部分?你能说出特别令人困惑的解释吗? – joran

+0

是不是因为文件解压缩成RGB(3通道)? – daniel

回答

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. 
+0

谢谢,但我仍然有一个问题。我的图像是grauscale(实际上它只有两种颜色,黑色或白色),所以R为什么看到它与3 chanells而不是1的图像?我得到值为0-1的矩阵(它们完全相同)。有什么方法可以改变它吗? – jjankowiak

相关问题