using Images, TestImages, LinearAlgebra, Plots img_path = "C:\\Users\\User\\Downloads\\SVD_PAPER\\Orca HD image.jpg" img = load(img_path) img = float.(img) channels = channelview(img) function rank_approx(F::SVD, k) U, S, V = F M = U[:, 1:k] * Diagonal(S[1:k]) * V[:, 1:k]' clamp01!(M) end # SVD on each color channel svdfactors = svd.(eachslice(channels; dims=1)) # Compress with different ranks imgs = map((10, 50, 100)) do k colorview(RGB, rank_approx.(svdfactors, k)...) end plot(mosaicview(img, imgs...; nrow=1, npad=10))