This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedfilt_rapid-1.m
91 lines (57 loc) · 1.61 KB
/
medfilt_rapid-1.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
% function to make fast 2D median combining image rescaling with medfilt2
% using the same input parameters than medfilt2, but allowing replicate
% padding
% origin Paul Tafforeau ESRF 05/2010
function im2=medfilt_rapid(im,varargin)
repetition=2; % number of pass to avoid aliasing
speed_factor=3; % general acceleration factor (important for large filter sizes)
switch (nargin)
case 1
HS=3;
VS=3;
padding_rapid='symmetric';
case 2
filter_size=varargin{1};
HS=filter_size(1);
VS=filter_size(2);
padding_rapid='symmetric';
case 3
filter_size=varargin{1};
HS=filter_size(1);
VS=filter_size(2);
padding_rapid=varargin{2};
end
X=size(im,1);
Y=size(im,2);
if strcmp(padding_rapid,'replicate')==1
im2=padarray(im,[HS-1 VS-1],'replicate','both');
padding='symmetric';
else
im2=im;
padding=padding_rapid;
end
X2=size(im2,1);
Y2=size(im2,2);
Hacceleration=max(log(HS)*speed_factor,1);
Vacceleration=max(log(VS)*speed_factor,1);
if HS>3
HS_size=floor(HS/Hacceleration/2)*2+1;
else
HS_size=HS;
end
if VS>3
VS_size=floor(VS/Vacceleration/2)*2+1;
else
VS_size=VS;
end
Vrescale=min(1/(VS/VS_size),1);
Hrescale=min(1/(HS/HS_size),1);
for i=1:repetition
im2=imresize(im2,[X2*Hrescale Y2*Vrescale],'bicubic');
im2=medfilt2(im2,[HS_size VS_size],padding);
im2=imresize(im2,[X2 Y2],'bicubic');
end
if strcmp(padding_rapid,'replicate')==1
im2=imcrop(im2,[VS HS Y-1 X-1]);
end
end