从矩阵显示图片的其他好方法? (图像()除外) [英] Other good ways to display picture from a matrix? (other than image())

查看:126
本文介绍了从矩阵显示图片的其他好方法? (图像()除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我有一个特征向量 vec ,这实际上是一张图片(拉伸)。为了展示它,我正在使用这篇文章的解决方案: image(matrix(vec,nrow) = height,ncol = width),axes = FALSE,col = grey(seq(0,1,length = 256))),但因为原点在左下角所以图片是旋转90°。我想我也可以移动原点但是R应该在MATLAB中有一个像 imshow 这样的函数,它更适合直接显示图片而不需要配置这么多,同时 image()用于可视化矩阵。那么,有这样的功能吗?谢谢。

Say, I have a feature vector vec, which is actually a picture (stretched). To show it, I am using the solution from this post: image(matrix(vec,nrow=height,ncol=width),axes = FALSE,col = grey(seq(0, 1, length = 256))), but because the origin is at the bottom left corner so the picture is rotated 90°. I think I can move the origin too but R should have a function like imshow in MATLAB which is more appropriate and direct for showing a picture without the need of configuring so much, while image() is for visualizing a matrix. So, is there such a function? Thank you.

推荐答案

通过 t()转置矩阵是解决方案:

Transposing your matrix by t() is the solution:

vec = runif(4096)
vec[1:500]=0
v = matrix(vec,nrow=height,ncol=width)
image(v,axes = FALSE,col = grey(seq(0, 1, length = 256)))

image(t(v),axes = FALSE,col = grey(seq(0, 1, length = 256)))

或翻转它:

image(t(v)[, nrow(v):1],axes = FALSE,col = grey(seq(0, 1, length = 256)))

这篇关于从矩阵显示图片的其他好方法? (图像()除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆