forked from Kuangxd/SNRCNN_Matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNRCNN.m
40 lines (35 loc) · 1.45 KB
/
SNRCNN.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
function img_c = SNRCNN(model, img_n)
img_n = img_n';
%% load CNN model parameters
load(model);
weights_conv1 = double(weights_conv1); weights_conv2 = double(weights_conv2); weights_conv3 = double(weights_conv3);
[conv1_patchsize2,conv1_filters] = size(weights_conv1);
[conv2_channels,conv2_patchsize2,conv2_filters] = size(weights_conv2);
conv2_patchsize = sqrt(conv2_patchsize2);
[conv3_channels,conv3_patchsize2] = size(weights_conv3);
conv3_patchsize = sqrt(conv3_patchsize2);
[hei, wid] = size(img_n);
%% conv1
conv1_data = zeros(hei, wid, conv1_filters);
for i = 1 : conv1_filters
conv1_data(:,:,i) = imfilter(img_n, weights_conv1(:,i), 'same', 'replicate');
conv1_data(:,:,i) = max(conv1_data(:,:,i) + biases_conv1(i), 0);
end
%% conv2
conv2_data = zeros(hei, wid, conv2_filters);
for i = 1 : conv2_filters
for j = 1 : conv2_channels
conv2_subfilter = reshape(weights_conv2(j,:,i), conv2_patchsize, conv2_patchsize);
conv2_data(:,:,i) = conv2_data(:,:,i) + imfilter(conv1_data(:,:,j), conv2_subfilter, 'same', 'replicate');
end
conv2_data(:,:,i) = max(conv2_data(:,:,i) + biases_conv2(i), 0);
end
%% conv3
conv3_data = zeros(hei, wid);
for i = 1 : conv3_channels
conv3_subfilter = reshape(weights_conv3(i,:), conv3_patchsize, conv3_patchsize);
conv3_data(:,:) = conv3_data(:,:) + imfilter(conv2_data(:,:,i), conv3_subfilter, 'same', 'replicate');
end
%% SNRCNN reconstruction
img_c = conv3_data(:,:) + biases_conv3;
img_c = img_c';