Compresión con SVD

svd_greco

lo he creado con

library(png)

tmp.file <- tempfile()
download.file("http://datanalytics.com/uploads/greco.png", tmp.file)
m <- readPNG(tmp.file)

svd.m <- svd(m)

filtra.svd <- function(svd, k){
  tmp <- svd
  tmp$d[(k+1):length(tmp$d)] <- 0
  res <- tmp$u %*% diag(tmp$d) %*% t(tmp$v)

  res[res > 1] <- 1
  res[res < 0] <- 0

  plot(1:2, type='n', xlab = "",
        ylab = "", xaxt = "n", yaxt = "n",
        main = paste(k, "primeras componentes", sep = " "))
  rasterImage(res, 1, 1, 2, 2)
}

layout(matrix(1:9, 3, 3, byrow = T))

sapply(c(1,2,3,5,10,15,20,30,50),
        function(k) filtra.svd(svd.m, k))