# Image compression using SVD in MATLAB

I have to compress an image using SVD. I did a few things, but all of them produced a black & white image. However, the output must be RGB. How can I compress an image without changing its original format?

• What sort of "few things" you did so far?
– jojek
Oct 15, 2014 at 8:38
• I assume that he has used SVD in a PCA fashion and RGB values as the features, applied a standard dimensionality reduction and obtained features in the reduced space (possibly a gray scale one - following a normalization step). Oct 15, 2014 at 8:48
• what do you mean by depends on image dimensions too much? Suppose m x n(the total number of pixels) is fixed, and also number of singular values are fixed. What dimensions should your image have to save the most space from compression? Nov 20, 2016 at 14:11

The typical thing to do is the low-rank approximation on separate channels. Assume that $C$ is a channel of the RGB image $I$:

rank = 10;
[U,S,V] = svd(C);
L = U(:,1:rank) * S(1:rank, 1:rank) * V(:, 1:rank)';


Now, L should be the compressed image. If you do this operation and compose the channels back, you should get a compressed RGB image.

However, such a method in my opinion is only good for mathematical understanding. It is not very practical due to the fact that it depends on image dimensions too much and cannot generate high SNR results. Or better stated, as you decrease rank, you drastically reduce the quality of the reconstruction. For this reason, one has to retain around ~50-100 components. Better methods doing this blockwise, or formulating the compression as an energy functional exist. Image denoising is a huge area of its own.

You might want to check some results with varying rank in this presentation.

Also, a similar question has already been asked; please follow the Stack Exchange discussion here.