在R - 矩阵变换镜像中转置图像

时间:2018-03-17 20:13:17

标签: r

我有一个数据框,我正在转换为矩阵。每行代表白色,灰色和黑色的图像。 enter image description here 图像对应于数字5.我想知道我错过的是数字5出现镜像了吗?

plotimage <- function(df,n, imageTitle) {
  convertedImage <- df
  matrx <- matrix(unlist(convertedImage[n,1:784]), byrow = T, nrow=28)
  image(col = gray(0:255/255), z = matrx)
}

plotimage(image5, 1600,"Image of 5")

我想要的输出

号码5未镜像。

谢谢,

enter image description here

1 个答案:

答案 0 :(得分:1)

那是因为image的(不寻常)方式:

  

请注意,图像将z矩阵解释为f(x [i],y [j])的表   值,使x轴对应行号,y轴对应   列号,底部是第1列,即90度   逆时针旋转传统的印刷布局a   基质

这就是你matrx被解释的方式。因此,写作

image(col = gray(0:255/255), z = matrx[nrow(matrx):1, ])

应该修复它。

相关问题