-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminFilt2_opt.m
40 lines (35 loc) · 1.18 KB
/
minFilt2_opt.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
%%=========================================================================
% Copyright © 2018, SoC Design Lab., Dong-A University. All Right Reserved.
%==========================================================================
% • Date : 2018/08/06
% • Author : Dat Ngo
% • Affiliation: SoC Design Lab. - Dong-A University
% • Design : 2-D Minimum Filter
%==========================================================================
function [minImg] = minFilt2_opt(inImg,sv2)
%MINFILT2 2-D minimum filter.
% sv2: filtering window size.
% slidingOp: sliding option, "sliding" or "distinct".
% Default parameters
switch nargin
case 2
% All arguments were provided, do nothing
case 1
sv2 = 5;
otherwise
warning('Please check input arguments!');
return;
end
[~,~,c] = size(inImg);
padsize = floor((sv2-1)/2);
paddedImg = padarray(inImg,[padsize,padsize],Inf);
H = true(sv2,sv2);
switch c
case 1 % grayscale image
temp = ordfilt2(paddedImg,1,H);
minImg = temp((sv2+1)/2:end-(sv2-1)/2,(sv2+1)/2:end-(sv2-1)/2);
otherwise
warning('Invalid input image!');
return;
end
end