フィルターのクリア

Trouble learning loops, sub-plotting, etc. for multiple iterations of SVD for image compression

1 回表示 (過去 30 日間)
justin
justin 2012 年 11 月 29 日
I am very new to MATLAB and programming in general, but I am struggling with some concepts regarding multiple images plotted at the same time.
I am trying to read an image into MATLAB, convert it to grayscale, use SVD and zero out the eigenvalues greater than some N, reconstruct the image and graph the difference/error. Thus far, this is what I have:
B=imread('images1.jpeg');
B=rgb2gray(B);
doubleB=im2double(B);%
%read the image and store it as matrix B, convert the image to a grayscale
%photo and convert the image to a class 'double'
[U,S,V]=svd(doubleB);
C=S;
for N=[2,5,10,25,50,100];
C(N+1:end,:)=0;
C(:,N+1:end)=0;
D=U*C*V';
%Use singular value decomposition on the image doubleB, create a new matrix
%C (for Compression diagonal) and zero out all entries above N, (which in
%this case is 100). Then construct a new image, D, by using the new
%diagonal matrix C.
imshow(D);
error=mean((doubleB(:)-D(:)).^2);
error;
plot(N,error);
end
As you can probably see I am very new to this, and I am not sure how to do "for" loops very well, even after reading the standard documentation. The desired output I am looking for is a single pannel with 6 images, each one reconstructed for the values of N listed, ideally with a title that shows which example it is, i/e the most out of focus image would be titled N=2, and so on.
Then, I would like to make a simple line plot of the mean squared error (error) and N with appropriate axes so that the curve shows the decrease in error as N increases.
Any help would be greatly appreciated. Self-teaching is not my forte!

回答 (1 件)

John Petersen
John Petersen 2012 年 11 月 29 日
編集済み: John Petersen 2012 年 11 月 29 日
N=[2,5,10,25,50,100];
for i = 1:length(N)
C(N(i)+1:end,:)=0;
C(:,N(i)+1:end)=0;
D=U*C*V';
%Use singular value decomposition on the image doubleB, create a new matrix
%C (for Compression diagonal) and zero out all entries above N, (which in
%this case is 100). Then construct a new image, D, by using the new
%diagonal matrix C.
imshow(D);
err(i)=mean((doubleB(:)-D(:)).^2); % error is a reserved word
end
plot(N,err);
  1 件のコメント
John Petersen
John Petersen 2012 年 11 月 29 日
Figure out what you need to do for one of the N cases. Once that is right, you can try to continue on with determining an error. Try initializing err
N=[2,5,10,25,50,100];
err = zeros(length(N),1);
for i = 1:length(N) ....

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by