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?