# NOT RUN {
# Load test image
data("tiger")
# Compute (column) randomized interpolative decompsition
# Note that the image needs to be transposed for correct plotting
out <- rid(t(tiger), k = 150)
# Show selected columns
tiger.partial <- matrix(0, 1200, 1600)
tiger.partial[,out$idx] <- t(tiger)[,out$idx]
image(t(tiger.partial), col = gray((0:255)/255), useRaster = TRUE)
# Reconstruct image
tiger.re <- t(out$C %*% out$Z)
# Compute relative error
print(norm(tiger-tiger.re, 'F') / norm(tiger, 'F'))
# Plot approximated image
image(tiger.re, col = gray((0:255)/255))
# }
Run the code above in your browser using DataLab