0

I need to plot the image from the matrix. I have the 4 by 4 matrix mat. I have tried to plot the image from the matrix as was recomended here.

mat <- matrix(c(255,255,255,255, 255,255,255,255, 255,255,255,255, 0,0,0,0), nrow = 4, ncol = 4)
png("simpleIm.png", width = nrow(mat) + 1, height = ncol(mat) + 1, units = "px")
par(mar = rep(0, 4))
image(mat, axes = FALSE, col = grey(seq(0, 1, length = 256)))
dev.off()

Update. Resulted image has width and height each 4 pixels. But I have the warring:

Warning message:
In png("simpleIm.png", width = nrow(img_new) + 1, height = ncol(img_new) +  :
  'width=5, height=5' are unlikely values in pixels

Could anyone please give an advice how to correct the code in order to its work without the warning message?

Community
  • 1
  • 1
Nick
  • 1,086
  • 7
  • 21
  • 2
    You may look at `?png`, where you see that the default height and width are each 480. Change them to your heart's content. – Heroka Feb 12 '16 at 14:33
  • @Heroka, thanks you for comment. I have updated my code and question because the warning message was generated. – Nick Feb 13 '16 at 02:46
  • The warning happens with small height and width values as they're unusual. Why is it a problem? – Heroka Feb 13 '16 at 07:36
  • @Heroka, thanks you. My test example is 4x4 martix. My work matrix has 100 colunms and 100 rows. Problem is solved. – Nick Feb 14 '16 at 14:20

0 Answers0