Singular Value Decomposition SVD Image Compression MATLAB compression rate

Source: Internet
Author: User

Image Compression Based on SVD

Based on MATLAB, the Singular Value Decomposition (SVD) is used for image compression, and the influence of the size distribution curve and number of singular values on the compression ratio is displayed synchronously. The key steps of Singular Value Decomposition for image compression are recorded in the image.

CompleteCodeAs follows:

% Change the image path of row 9th, the image format is not limited to % 3.1.3.1.12 yangxin_szu % clear all; clc; % Import image x = imread ('f: \ m_material \ egle.bmp '); If (SIZE (x, 3 )~ = 1) x = rgb2gray (x); end % Singular Value Decomposition [u s v] = SVD (double (x )); % plot the singular value distribution curve plot (DIAG (s), 'B-', 'linewidth', 3); Title ('singular value of the image matrix '); ylabel ('svd '); % image size [m n] = size (x); % rank of the image matrix = rank (double (x); % display the source image figure, subplot (, 1), imshow (x); image_rank = ['image Matrix Rank = 'int2str (rank)]; Title (image_rank, 'color ', 'B'); % cyclically change the number of Singular Values selected, dynamic observation of image compression effect % number of cycles it = 1; iter = (rank/4-1) /10 + 1; % Number of stored Singular Values k_store = ones (ITER); % compression ratio corresponding to the number of stored Singular Values cr_store = ones (ITER); For k = 1: 10: rank/4 k_store (IT) = K; % select K Singular Values and restore the source image r = U (:, 1: K) * s (1: k, 1: K) * V (:, 1: K) '; t = uint8 (r); % Show restoration result subplot (, 2), imshow (t ); svd_number = ['number of selected Singular Values = 'int2str (k)]; Title (svd_number, 'color', 'B'); % calculate the compression ratio src_elements = m * N; compress_elements = m * k + K * n; compress_ratio = (1-compress_elements/src_elements) * 100; cr_store (IT) = compress_ratio; it = It + 1; fprintf ('rank = % d: K = % d: compress_ratio = %. 2f \ n', rank, K, compress_ratio); % pause for 0.5 seconds, easy To observe effect pause (0.5); end % draw the relationship curve between the number of Singular Values and compression ratio figure, plot (k_store, cr_store, 'B-', 'linewidth', 3); Title ('relationship between the number of Singular Values and the compression ratio '); xlabel ('singular value number '); ylabel ('Compression ratio ');

 

ProgramRunning result:

Source image:

Distribution curve of the singular value size:

The Effects of Different Singular Values on image compression ratio:

Relationship between the number of Singular Values and the image compression ratio:

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.