-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavelet_denoising.m
94 lines (75 loc) · 3.04 KB
/
wavelet_denoising.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% ------------------------------------------------------------------------------
%
% Author: Helder C. R. Oliveira
%
% Copyright (c) Helder Oliveira, 2015
% Email: [email protected]
%
% ------------------------------------------------------------------------------
function [ img_out ] = wavelet_denoising(img, factor)
wave_name = 'db4';
nivel_dec = 5;
anscombe = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ANSCOMBE -> FORWARD
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (anscombe == 1)
img_2_proc = Anscombe_forward(img);
else
img_2_proc = img;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wavelet Forward
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% X% da dose
[cA_X, cH_X, cV_X, cD_X, tams_X] = wavelet_dec(img_2_proc, nivel_dec, wave_name);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THRESHOLDING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for nivel = 1:1:nivel_dec,
fprintf('\n-> Nivel: %d\n', nivel);
% k == 3, citado no livro do Starck
% |w| <= k*sigma <--- threshold
k = 1.5;
% Threshold local, na sub-banda
t_h = wavelet_threshold(cH_X{nivel}, 'visushrink') * k;
t_v = wavelet_threshold(cV_X{nivel}, 'visushrink') * k;
t_d = wavelet_threshold(cD_X{nivel}, 'visushrink') * k;
% H-Threshold
% Escala os coeficientes dentro do intervalo de threshold: [-t, t]
[R, C] = size(cH_X{nivel});
% Fator de Shrinkage dos coeficientes
% factor = 0.7;
for iR = 1:1:C
for iC = 1:1:R
v1 = abs(cH_X{nivel}(iC, iR));
v2 = abs(cV_X{nivel}(iC, iR));
v3 = abs(cD_X{nivel}(iC, iR));
if (v1 < t_h)
cH_X{nivel}(iC, iR) = (cH_X{nivel}(iC, iR)) * factor;
end
if (v2 < t_v)
cV_X{nivel}(iC, iR) = (cV_X{nivel}(iC, iR)) * (factor);
end
if (v3 < t_d)
cD_X{nivel}(iC, iR) = (cD_X{nivel}(iC, iR)) * factor;
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reconstruction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = wavelet_rec(cA_X, cH_X, cV_X, cD_X, ...
nivel_dec, wave_name, tams_X);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ANSCOMBE <- INVERSE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if anscombe == 1,
img = Anscombe_inverse_exact_unbiased(img);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Recortes onde existem microcalcificacoes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img_out = img;
end