www.pudn.com > demo.zip > quzao.m, change:2012-04-15,size:2842b


clear; 
clc; 
 
param.L = 3;   % number of elements in each linear combination. 
param.K =300; % number of dictionary elements 
param.numIteration = 50; % number of iteration to execute the K-SVD algorithm. 
 
param.errorFlag = 0; % decompose signals until a certain error is reached. do not use fix number of coefficients. 
%param.errorGoal = sigma; 
param.preserveDCAtom = 0; 
param.InitializationMethod =  'DataElements'; 
 
 segmented_images=fenge(); 
 g1=segmented_images{1}; 
 g2=segmented_images{2}; 
 g3=segmented_images{3}; 
 
%  g1=cell2mat(segmented_images(:,1)); 
%  g2=cell2mat(segmented_images(:,2)); 
%  g3=cell2mat(segmented_images(:,3)); 
IMin=[g1,g2,g3]; 
figure(); 
imshow(IMin); 
%  
 X=imnoise(IMin,'salt & pepper',0.01);  
%  X=imnoise(IMin,'gaussian',0.02)  
 figure(); 
 imshow(X); 
%  
 bb=8; % block size 
 RR=4; % redundancy factor 
 K=RR*bb^2; % number of atoms in the dictionary 
sigma =16;  
% % if (length(size(G))>2) 
% %     G = rgb2gray(G); 
% % end 
% % if (max(G(:))<2) 
% %   G = G*255; 
% % end 
% % G=im2double(G); 
% % % h=sigma*randn(size(g1)); 
% % IMin=G+sigma*randn(size(G)); 
% % PSNRIn = 20*log10(255/sqrt(mean((IMin(:)-G(:)).^2))); 
%  
% % if (length(size(g2))>2) 
% %     g2 = rgb2gray(g2); 
% % end 
% % if (max(g2(:))<2) 
% %    g2 = g2*255; 
% % end 
% % g2=im2double(g2); 
% % IMin2=g2+sigma*randn(size(g2)); 
% % PSNRIn2= 20*log10(255/sqrt(mean((IMin2(:)-g2(:)).^2))); 
% %  
% % if (length(size(g3))>2) 
% %     g3 = rgb2gray(g3); 
% % end 
% % if (max(g3(:))<2) 
% %    g3 = g3*255; 
% % end 
% % g3=im2double(g3); 
% %  
% % IMin3=g3+sigma*randn(size(g3)); 
% % PSNRIn3 = 20*log10(255/sqrt(mean((IMin3(:)-g3(:)).^2))); 
% % IMin=[IMin1,IMin2,IMin3]; 
% %  G=[g1,g2,g3]; 
% % %  
% %  
IMin = rgb2gray(IMin); 
IMin=im2double(IMin); 
 
% IMin=[g1,g2,g3]; 
%  G=g1+g2+g3; 
%  figure(); 
%  imshow(G); 
 
X = rgb2gray(X); 
X=im2double(X); 
figure(); 
imshow(IMin); 
figure(); 
imshow(X); 
%  
 
PSNRIn = 20*log10(255/sqrt(mean((X(:)-IMin(:)).^2))); 
 
[IoutAdaptive,output] = denoiseImageKSVD(X, sigma,K); 
 
PSNROut = 20*log10(255/sqrt(mean((IoutAdaptive(:)-X(:)).^2))); 
figure; 
% subplot(1,3,1); imshow(IMin0,[]); title('Original clean image'); 
subplot(1,2,1); imshow(X,[]); title(strcat(['Noisy image, ',num2str(PSNRIn),'dB'])); 
subplot(1,2,2); imshow(IoutAdaptive,[]); title(strcat(['Clean Image by Adaptive dictionary, ',num2str(PSNROut),'dB'])); 
%  
% IoutAdaptive=[p1,p2,p3]; 
% P=p1+p2+p3; 
% figure(); 
% imshow(P,[]); title('ԭͼ '); 
 
figure(); 
I = displayDictionaryElementsAsImage(output.D, floor(sqrt(K)), floor(size(output.D,2)/floor(sqrt(K))),bb,bb); 
title('The dictionary trained on patches from the noisy image'); 
 
Y=IoutAdaptive; 
% [p1,p2,p3]=Y; 
p1=Y(:,1:300); 
p2=Y(:,301:600); 
p3=Y(:,601:900); 
P=p1+p2+p3; 
figure(); 
imshow(P);title('ԭͼ ');