This section describes how to use Singular Value Decomposition to compress images. A blog post in the first half of this year posted a program for processing PCA problems using Singular Value Decomposition. At that time, we used image sequences to separate different parts of the image sequences. This is not an image sequence, but an image. Therefore, the image matrix is directly SVD.
Wu Jun's beauty of mathematics has already introduced how to use SVD to compress big data. However, I 'd like to introduce the image here. For example, a 1000*1000 image a requires 1000000 pixels for storage. If we perform SVD decomposition on A, then a = usv '. If rank (A) = r, U is the 1000 * r matrix, and s is the R * r matrix, V is the matrix of 1000 * r. Therefore, the stored data is the number of 1000 * r + R * r + 1000 * R. If this R is small, the storage space will be much smaller. Of course, if R = 1000, then calculating SVD is a waste of space and time. So when using this SVD, we should first look at its rank as well.
The program and running result are given below. Here we use different feature components to reconstruct the original image. Let's take a look at the effect. (The tragic rank here is the width of the source image)
clear all;close all;clc;a=imread('lena.jpg');imshow(mat2gray(a))[m n]=size(a);a=double(a);r=rank(a);[s v d]=svd(a);%re=s*v*d';re=s(:,:)*v(:,1:1)*d(:,1:1)';figure;imshow(mat2gray(re));imwrite(mat2gray(re),'1.jpg')re=s(:,:)*v(:,1:20)*d(:,1:20)';figure;imshow(mat2gray(re));imwrite(mat2gray(re),'2.jpg')re=s(:,:)*v(:,1:80)*d(:,1:80)';figure;imshow(mat2gray(re));imwrite(mat2gray(re),'3.jpg')re=s(:,:)*v(:,1:150)*d(:,1:150)';figure;imshow(mat2gray(re));imwrite(mat2gray(re),'4.jpg')
Below is:
Lena source Image
Reconstruction with only 1st feature values
Refactor with the first 10 feature values
Refactor with the first 80 feature values
Reconstruct with the first 150 feature values
Finally, some applications of Singular Value Decomposition are described as follows:
1. Image Compression, as shown above.
2. noise filtering.
3. pattern recognition. Because SVD is the main component for extraction.
4. biological, physical, and economic statistical model processing.