-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremove_edge_objects.m
More file actions
23 lines (15 loc) · 836 Bytes
/
remove_edge_objects.m
File metadata and controls
23 lines (15 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function cleaned_binary = remove_edge_objects(threshed_image)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Setup variables and parse command line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i_p = inputParser;
i_p.addRequired('threshed_image',@(x)isnumeric(x) || islogical(x));
i_p.parse(threshed_image);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main Program
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
edge_border = ones(size(threshed_image));
edge_border = bwperim(edge_border);
[row_indexes,col_indexes] = ind2sub(size(threshed_image), find(edge_border));
edge_objects = bwselect(threshed_image,col_indexes,row_indexes,4);
cleaned_binary = threshed_image & not(edge_objects);