forked from csjunxu/WNNM_CVPR2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo_Real.m
71 lines (71 loc) · 2.68 KB
/
Demo_Real.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
65
66
67
68
69
70
71
clear;
Original_image_dir = 'C:/Users/csjunxu/Desktop/CVPR2017/DSCDL_BID/TestedImages/';
fpath = fullfile(Original_image_dir, 'coffee_middle.png');
im_dir = dir(fpath);
im_num = length(im_dir);
%% the whole image or part
type = 'middle';
for i = 1:im_num
IMin = im2double(imread(fullfile(Original_image_dir, im_dir(i).name)));
S = regexp(im_dir(i).name, '\.', 'split');
IMname = S{1};
fprintf('%s : \n',IMname);
% color or gray image
[h,w,ch] = size(IMin);
fprintf('%s : \n',IMname);
hh = [0:1000:h,h];
ww = [0:1000:w,w];
num_part = 0;
if strcmp(type, 'all')
listh = 1 : length(hh)-1;
listw = 1 : length(ww)-1;
IMout = zeros(h,w,ch);
elseif strcmp(type, 'random')
listh = randi([1, length(hh)-1],1,1);
listw = randi([1, length(ww)-1],1,1);
IMout = zeros(1000,1000,3);
elseif strcmp(type, 'middle')
listh = floor(median(1:length(hh)-1));
listw = floor(median(1:length(ww)-1));
IMout = zeros(1000,1000,3);
end
%%
for nh = listh
for nw = listw
num_part = num_part + 1;
fprintf('Part %d/%d : \n',num_part, (length(hh)-1)*(length(ww)-1));
IMin_part = IMin(hh(nh)+1:hh(nh+1),ww(nw)+1:ww(nw+1),:);
% color or gray image
if ch==1
IMin_part_y = IMin_part;
else
% change color space, work on illuminance only
IMin_part_ycbcr = rgb2ycbcr(IMin_part);
IMin_part_y = IMin_part_ycbcr(:, :, 1);
IMin_part_cb = IMin_part_ycbcr(:, :, 2);
IMin_part_cr = IMin_part_ycbcr(:, :, 3);
end
%% denoising
nSig = NoiseLevel( IMin_part_y *255);
Par = ParSet(nSig);
IMout_part_y = WNNM_DeNoising( IMin_part_y, IMin_part_y, Par );
if ch==1
IMout_part = IMout_part_y;
else
IMout_part_ycbcr = zeros(size(IMin_part));
IMout_part_ycbcr(:, :, 1) = IMout_part_y;
IMout_part_ycbcr(:, :, 2) = IMin_part_cb;
IMout_part_ycbcr(:, :, 3) = IMin_part_cr;
IMout_part = ycbcr2rgb(IMout_part_ycbcr);
end
fprintf('This is the %d/%d part of the image %s.%s!\n',num_part,(length(hh)-1)*(length(ww)-1),IMname,S{2});
if strcmp(type, 'all')
IMout(hh(nh)+1:hh(nh+1),ww(nw)+1:ww(nw+1),:) = IMout_part;
elseif strcmp(type, 'random') || strcmp(type, 'middle')
IMout = IMout_part;
end
end
end
%% output
imwrite(IMout, ['C:/Users/csjunxu/Desktop/CVPR2017/1_Results/WNNM_' IMname '.png']);
end