-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_empty.m
47 lines (43 loc) · 1.04 KB
/
delete_empty.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
function out = delete_empty(in)
low_ind = -1;
high_ind = 0;
for j = 1:size(in, 2)
if sum(in(:, j)) ~= 0
if low_ind == -1
low_ind = j;
end
high_ind = j;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if low_ind == -1 || high_ind == 0
in = in(:, 1:4);
in = 1 - in;
warning('empty image')
else
in = in(:, low_ind:high_ind);
end
low_ind = -1;
high_ind = 0;
for j = 1:size(in, 1)
if sum(in(j, :)) ~= 0
if low_ind == -1
low_ind = j;
end
high_ind = j;
end
end
if low_ind == -1 || high_ind == 0
in = in(:, 1:4);
in = 1 - in;
low_ind = 1;
high_ind = 4;
warning('empty image')
end
if strcmp(class(in), 'logical')
in = in(low_ind:high_ind, :);
else
in = im2bw(in(low_ind:high_ind, :));
end
out = in;
end