-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDemo_SS_GMM.m
64 lines (35 loc) · 1.42 KB
/
Demo_SS_GMM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
clear;
close all
% Add path for auxiliary functions
addpath('./funcs');
% Set the random number generator
reset(RandStream.getGlobalStream);
% Determine the experiment setting
nSig0 = 15/255; % noise level
% Load the test image and Genenrate the corresponding noisy image
path_Img = './Monarch.png';
O_Img = imread(path_Img);
O_Img = double(O_Img)/255;
N_Img = O_Img + nSig0 * randn(size(O_Img));
% Print the psnr of the noisy image to be processed
PSNR = csnr( O_Img*255, N_Img*255, 0, 0 );
fprintf( 'Noisy Image: nSig = %2.3f, PSNR = %2.2f \n', nSig0*255, PSNR );
% Set parameters for SS-GMM
Par = setpar(N_Img);
% Learn the image prior with the SS-GMM
[Par.nSig, model] = SS_GMM(N_Img, Par);
% Store the trained model
path_model = 'prior.mat';
save(path_model, 'model', 'Par');
% Denoise the image with learned prior using the EPLL framework
Par.O_Img = O_Img; % Uncomment to calculate PSNRs for intermediate results
E_Img = EPLL_GMM(N_Img, model, Par);
% Print information of processed result
E_Img(E_Img<0) = 0;
E_Img(E_Img>1) = 1;
PSNR = csnr( O_Img*255, E_Img*255, 0, 0 );
fprintf( 'Estimated Image: nSig = %2.3f, PSNR = %2.2f \n\n', sqrt(Par.nSig)*255, PSNR );
% Store the denoised result in PNG format
imwrite(uint8(E_Img*255), 'img_denoised.png');
% Remove path for auxiliary functions
rmpath('./funcs');