-
Notifications
You must be signed in to change notification settings - Fork 2
/
opterode.m
41 lines (39 loc) · 1.36 KB
/
opterode.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
function B = opterode(A,se)
%% Modified Version of MATLAB's built-in imerode
%
% B = opterode(A,se)
%
% Details This is a modified form of MATLAB's built-in imerode that has
% been optimised for 2D images with flat structural elements and
% was implemented for the paper 'A New Method for Ellipse
% Detection' by Carl J. Nelson, Philip T. G. Jackson and
% Boguslaw Obara in 2015.
% Inputs A - 2D image (grayscale or BW)
% N - structural element; must be flat
% Outputs B - eroded 2D image (grayscale or BW)
%
% Examples:
% A = rand(20);%Starting image - random
% se = strel('disk',4,0);%Structural element - disk (N.B. flat)
% B = opterode(A,se), returns grayscale image B same size as A
%
% License See included <a href="./LICENSE/">file</a> or visit
% <a href="https://github.com/ChasNelson1990/...
% A-New-Method-for-Ellipse-Detection-2015/">The GitHub
% Repository</a>
%% Pad with Zeros (c.f. MATLAB's default of Inf)
[m,n] = size(A);
[sm,sn] = size(se);
B = zeros(m+(2*sm),n+2*sn);
B(sm+(1:m),sn+(1:n)) = A;
%% Apply Erosion
height = zeros([sm,sn]);
if islogical(A)
B = logical(B);
B = images.internal.morphmex('erode_binary_twod', B, se, height, -1);
else
B = images.internal.morphmex('erode_gray_flat', B, se, height, -1);
end
%% Remove Padding
B = B(sm+(1:m),sn+(1:n));
end