我在R中有一个带有这些值的3d矩阵:
mypixels=c(rep(1,8),rep(0,40))
mymatrix=array(mypixels,dim=c(4,4,3))
structure(mymatrix)
, , 1
[,1] [,2] [,3] [,4]
[1,] 1 1 0 0
[2,] 1 1 0 0
[3,] 1 1 0 0
[4,] 1 1 0 0
, , 2
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 0 0 0 0
[3,] 0 0 0 0
[4,] 0 0 0 0
, , 3
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 0 0 0 0
[3,] 0 0 0 0
[4,] 0 0 0 0
应用此订单:
writeJPEG(mymatrix,"mypicture.jpg",quality = 1)
预计将生成一半的红色图像,另一半生成黑色。但是,图像显示由四个不同的列组成,显示从红色到黑色的从左到右的渐变。事实上,阅读该图片显示:
mymatrix2=readJPEG("mypicture.jpg")
structure(mymatrix2)
, , 1
[,1] [,2] [,3] [,4]
[1,] 0.9960784 0.8 0.1490196 0
[2,] 0.9960784 0.8 0.1490196 0
[3,] 0.9960784 0.8 0.1490196 0
[4,] 0.9960784 0.8 0.1490196 0
, , 2
[,1] [,2] [,3] [,4]
[1,] 0.007843137 0.08627451 0 0.01568627
[2,] 0.007843137 0.08627451 0 0.01568627
[3,] 0.007843137 0.08627451 0 0.01568627
[4,] 0.007843137 0.08627451 0 0.01568627
, , 3
[,1] [,2] [,3] [,4]
[1,] 0 0.08235294 0 0.01568627
[2,] 0 0.08235294 0 0.01568627
[3,] 0 0.08235294 0 0.01568627
[4,] 0 0.08235294 0 0.01568627
将质量更改为0.5会产生类似的结果(尽管值略有不同)。那么,我怎样才能获得100%的质量,也就是说,在写入图像时没有改变颜色值?