using Images, TestImages, LinearAlgebra, Plots img_path = "C:\\Users\\User\\Downloads\\SVD_PAPER\\cats_medium.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 # Apply SVD separately to each color channel svdfactors = svd.(eachslice(channels; dims=1)) # Create compressed RGB images for k = 10, 50, 100 imgs = map((10, 50, 100)) do k colorview(RGB, rank_approx.(svdfactors, k)...) end plot(mosaicview(img, imgs...; nrow=1, npad=10))