Created
November 14, 2016 16:03
-
-
Save jxnl/2407f87ffbc950d4c7a16dc9a544a33e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [cmpImg] = svdCompress(img,k) | |
| % Obtains SVD | |
| [u,s,v] = svd(img); | |
| % Vectorized sum of k rank one matrices | |
| cmpImg = u(:,1:k)*s(1:k,1:k)*v’(1:k,:); | |
| end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [normError] = svdVisualize(FILENAME,k,plot) | |
| % Loads Image and takes one of RBG matrix | |
| img = imread(FILENAME)(:,:,1); | |
| % Obtains SVD | |
| [u,s,v] = svd(img); | |
| % Vectorized sum of rank = k Matrix | |
| cmpImg = uint8(u(:,1:k)*s(1:k,1:k)*v’(1:k,:)); | |
| if plot == 1 | |
| % original image | |
| subplot(1,3,1); | |
| image(img./5) | |
| axis off | |
| % compressed image of rank k | |
| subplot(1,3,2); | |
| image(cmpImg./5) | |
| axis off | |
| % difference error | |
| subplot(1,3,3); | |
| image(img-cmpImg); | |
| axis off | |
| else | |
| errMatrix = double(img-cmpImg); | |
| normError = norm(errMatrix); | |
| end | |
| end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment