Applications of SVD: image compression
Images as matricesWe can represent images as matrices, as follows. Consider an image having
The image can be visualized in matlab as well. We must first transform the matrix from integer to double. In JPEG format, the image will be loaded into matlab as a three-dimensional array, one matrix for each color. For gray scale images, we only need the first matrix in the array. Matlab syntax
>> A = imread(baboon-grayscale.jpg); % loads image in integer format as a 3d-array >> A = double(A); % transform to real values >> A = A(:,:,1); % for gray-scale images, we consider only the first matrix in the array Low-rank approximationUsing the low-rank approximation via SVD method, we can form the best rank- Matlab syntax
>> [U,S,V] = svd(A); >> Ak = U(:,1:k)*S(1:k,1:k)*V(:,1:k)';
Recall that the explained variance of the rank-
|