Computer >> Computer tutorials >  >> Programming >> Javascript

How to create an image of matrix of pixels in R?


A matrix can be converted into a pixel’s image of matrix. It is defined as the area of the matrix which contains pixels with equal or different sizes of left, right, bottom and upper.

We can create this by using image function and its argument useRaster with the matrix data.

Example

 

> M<-matrix(rnorm(100,1.5),nrow=10)
> par(mar=c(5,5,5,5))
> image(M,useRaster=TRUE,axes=FALSE)

Output

How to create an image of matrix of pixels in R?

> par(mar=c(10,10,10,10))
> image(M,useRaster=TRUE,axes=FALSE)

Output

How to create an image of matrix of pixels in R?

> par(mar=c(2,2,2,2))
> image(M,useRaster=TRUE,axes=FALSE)

Output

How to create an image of matrix of pixels in R?

Pixel matrix with grey color −

> image(M,axes=FALSE,col=grey(seq(0,1,length=180)))

Output

How to create an image of matrix of pixels in R?