我想显示存储为二进制文件的灰度图像。我尝试了图像和光栅图像功能,但输出的质量比原始的差。下面是我的代码示例:
finfo=file.info(“image_file”)。
toread=file(“image_file”,“rb”)。
image_data=readbin(toread,integer(),size=1,n=finfo$size,endian=“little”)。
img_m<-矩阵(图像数据,nrow=480,ncol=640)
图像(数据_m,轴=假,col=灰色(seq(0,1,length=256)))
< /代码>
上面代码的输出如下所示:
![](“https://i.stack.imgur.com/vwiv9.png”alt=“enter)
但是,原始图像如下所示:
![](“https://i.stack.imgur.com/wuxql.png”alt=“enter)
我使用image.frombytes函数对python进行了同样的尝试,它正确地显示了图像。我没能和R做同样的事。
更新:我将前150000像素设置为0,只是为了看看它是否会正确地影响显示,而不是黑色像素,我得到了灰色像素。图片如下:
![](“https://i.stack.imgur.com/aatdi.png”alt=“enter)
有人知道正确显示它的正确函数吗,或者我的代码中缺少什么来获得正确的图像?
我很感激你对这件事有任何的见解。原始的。下面是我的代码示例:
finfo=file.info("image_file")
toread= file("image_file","rb")
image_data = readBin(toread, integer(), size=1, n = finfo$size, endian="little")
img_m<-matrix(image_data,nrow=480,ncol=640)
image(data_m,axes=FALSE,col=grey(seq(0,1,length=256)))
上面代码的输出如下所示:
![enter image description here](https://i.stack.imgur.com/VwIV9.png)
但是,原始图像如下所示:
![enter image description here](https://i.stack.imgur.com/wuXql.png)
我使用image.frombytes函数对python进行了同样的尝试,它正确地显示了图像。我没能用R做同样的事。
更新:我将前150000像素设置为0,只是为了看看它是否会正确地影响显示,而不是黑色像素,我得到了灰色像素。图片如下:
![enter image description here](https://i.stack.imgur.com/aatDI.png)
有人知道正确显示它的正确函数吗,或者我的代码中缺少什么来获得正确的图像?
我很欣赏你对此的任何见解。