-
Notifications
You must be signed in to change notification settings - Fork 27
/
cnn_CT_denoising_forward_process.m
66 lines (47 loc) · 2.07 KB
/
cnn_CT_denoising_forward_process.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
function recon = cnn_CT_denoising_forward_process(net,noisy,lv,dflt,patchsize,batchsize,overlap,wgt,gpus)
ind = 1 : size(noisy,3);
noisyCoeffs = single(cnn_wavelet_decon(double(noisy),lv,dflt));
noisyCoeffs = noisyCoeffs .*wgt;
[ny, nx] = size(noisy);
wgtMap = zeros(ny, nx, 'single');
reconCoeffs = zeros(size(noisyCoeffs),'single');
if gpus > 0
reconCoeffs = gpuArray(reconCoeffs);
end
for y = 1:(patchsize-overlap):ny-1
yy = min(y, ny-patchsize+1);
for x = 1:(patchsize-overlap):nx-1
xx = min(x,nx-patchsize+1);
wgtMap(yy:(yy+patchsize-1),xx:(xx+patchsize-1),:) = ...
wgtMap(yy:(yy+patchsize-1),xx:(xx+patchsize-1),:) +1;
for tt = 1:ceil(length(ind)/batchsize)
ind_s = batchsize*(tt-1)+1;
ind_e = min(length(ind),ind_s+batchsize-1);
noisyCoeffsSub = noisyCoeffs(yy:(yy+patchsize-1),xx:(xx+patchsize-1),:,ind_s:ind_e);
if gpus > 0
noisyCoeffsSub = gpuArray(noisyCoeffsSub);
res = vl_simplenn_modified(net,single(noisyCoeffsSub),[],[],...
'mode','test',...
'conserveMemory', 1, ...
'cudnn', 1);
else
res = vl_simplenn_modified(net,single(noisyCoeffsSub),[],[],...
'mode','test',...
'conserveMemory', 1);
end
reconCoeffsSub = res(end-1).x;
reconCoeffs(yy:(yy+patchsize-1),xx:(xx+patchsize-1),:,ind_s:ind_e) =...
reconCoeffs(yy:(yy+patchsize-1),xx:(xx+patchsize-1),:,ind_s:ind_e) + reconCoeffsSub;
end
end
end
wgtMap = repmat(wgtMap, [1, 1, size(reconCoeffs,3)]);
if gpus > 0
reconCoeffs = gather(reconCoeffs);
end
for tt = 1: size(reconCoeffs,4)
reconCoeffs(:,:,:,tt) = reconCoeffs(:,:,:,tt)./wgtMap;
end
reconCoeffs = reconCoeffs + noisyCoeffs;
recon = single(cnn_wavelet_recon(double(reconCoeffs./wgt),lv,dflt));
recon(recon < 0) = 0;