0

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.

Community
  • 1
  • 1
Ziyuan
  • 4,215
  • 6
  • 48
  • 77
  • Can you provide us your vec? – Ali Nov 09 '12 at 15:18
  • @Ali the size of the picture is 64x64 so the dimension is 4096. The vector is here http://pastebin.com/Pnz7p0Ac – Ziyuan Nov 09 '12 at 15:36
  • ziyuang: tip for reproducibility: use `(1:64), seq(), runif(), rnorm()` etc. to compactly generate a sample vector, just give us a general idea what we're dealing with. Post that here not on pastebin. – smci Apr 12 '14 at 01:25
  • See also: http://stackoverflow.com/questions/21684942/image-vs-ggplot-how-to-plot-color-legend – smci Apr 12 '14 at 02:01

1 Answers1

4

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)))

enter image description here

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

enter image description here

Or to flip it:

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

enter image description here

Ali
  • 9,440
  • 12
  • 62
  • 92