-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutColorImageMargin.m
More file actions
37 lines (34 loc) · 1.05 KB
/
cutColorImageMargin.m
File metadata and controls
37 lines (34 loc) · 1.05 KB
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
function cutRect = cutColorImageMargin(img)
height = size(img, 1);
width = size(img, 2);
margin = img(:, :, 1) == 255 & img(:, :, 2) == 255 & img(:, :, 3) == 255;
tmp = margin(:, :);
flag1 = true;
flag2 = true;
breakFlag = false;
for i = 1:width
for j = 1:height
if flag1 == true
if tmp(j, i) ~= 1
startPoint{1} = j;
startPoint{2} = i;
flag1 = false;
end
end
if flag2 == true
if tmp(height - j + 1, width - i + 1) ~= 1
endPoint{1} = height - j + 1;
endPoint{2} = width - i + 1;
flag2 = false;
end
end
if flag1 == false && flag2 ==false
breakFlag = true;
end
end
if breakFlag == true
break;
end
end
cutRect = img(startPoint{1}:endPoint{1}, startPoint{2}:endPoint{2}, :);
end