Perform the following steps to compress an image with SVD:
- First, install and load bmp:
> install.packages("bmp") > library(bmp)
- You can then read the image of Lenna as a numeric matrix with the read.bmp function. When the reader downloads the image, the default name is lena512.bmp:
> lenna = read.bmp("lena512.bmp")
- Rotate and plot the image:
> lenna = t(lenna)[,nrow(lenna):1] > image(lenna)
- Next, you can perform SVD on the read numeric matrix and plot the percentage of variance explained:
> lenna.svd = svd(scale(lenna)) > plot(lenna.svd$d^2/sum(lenna.svd$d^2), type="l", xlab=" Singularvector", ...