how to convert a JPEG to an image matrix in R

2020-07-18 05:19发布

问题:

I need to convert a JPEG image to a matrix. I want to run SVD on the matrix.

I had used

library(jpeg)
library(biOps)
myjpg <- readJpeg("Snapshot_1.jpg")
> dim(myjpg)
[1] 398 506   3

I want to get an image matrix of "myjpg" in grey scale preferably. Is there an R command which does that.

Thanks

回答1:

You are looking for:

imagedata(myjpg, type="grey")