-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxfilt2.m
65 lines (59 loc) · 1.74 KB
/
maxfilt2.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
function Y = maxfilt2(X,varargin)
% MAXFILT2 Two-dimensional max filter
%
% Y = MAXFILT2(X,[M N]) performs two-dimensional maximum
% filtering on the image X using an M-by-N window. The result
% Y contains the maximun value in the M-by-N neighborhood around
% each pixel in the original image.
% This function uses the van Herk algorithm for max filters.
%
% Y = MAXFILT2(X,M) is the same as Y = MAXFILT2(X,[M M])
%
% Y = MAXFILT2(X) uses a 3-by-3 neighborhood.
%
% Y = MAXFILT2(..., 'shape') returns a subsection of the 2D
% filtering specified by 'shape' :
% 'full' - Returns the full filtering result,
% 'same' - (default) Returns the central filter area that is the
% same size as X,
% 'valid' - Returns only the area where no filter elements are outside
% the image.
%
% See also : MINFILT2, VANHERK
%
% Initialization
[S, shape] = parse_inputs(varargin{:});
% filtering
Y = vanherk(X,S(1),'max',shape);
Y = vanherk(Y,S(2),'max','col',shape);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [S, shape] = parse_inputs(varargin)
shape = 'same';
flag = [0 0]; % size shape
for i = 1 : nargin
t = varargin{i};
if strcmp(t,'full') & flag(2) == 0
shape = 'full';
flag(2) = 1;
elseif strcmp(t,'same') & flag(2) == 0
shape = 'same';
flag(2) = 1;
elseif strcmp(t,'valid') & flag(2) == 0
shape = 'valid';
flag(2) = 1;
elseif flag(1) == 0
S = t;
flag(1) = 1;
else
error(['Too many / Unkown parameter : ' t ])
end
end
if flag(1) == 0
S = [3 3];
end
if length(S) == 1;
S(2) = S(1);
end
if length(S) ~= 2
error('Wrong window size parameter.')
end