## Read in image
X <- as.matrix(read.delim("tukey.txt"))
col <- gray.colors(256,start=0,end=1,gamma=1)
image(X,col=col)

## SVD
S <- svd(X)
U <- S$u
D <- diag(S$d)
V <- S$v

## Plot approximations of the true image
plotme <- function(q){image(U[,1:q]%*%tcrossprod(D[1:q,1:q],V[,1:q]),col=col,main=paste(q," components"))}
par(mfrow=c(3,3))
plotme(1)
plotme(2)
plotme(4)
plotme(8)
plotme(16)
plotme(32)
plotme(64)
plotme(225)
