-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_vertical_seam.m
34 lines (29 loc) · 952 Bytes
/
find_vertical_seam.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
function verticalSeam = find_vertical_seam(cumulativeEnergyMap)
[rowNum,colNum] = size(cumulativeEnergyMap);
[~,colInd] = min(cumulativeEnergyMap(end,:)); % find the minimum pixel in the last row and its index
verticalSeam = zeros(1,rowNum); % intialize the vertical seam
verticalSeam(1,rowNum) = colInd; % the column index for last row
s1 = Inf;
s2 = Inf;
s3 = Inf;
for i=rowNum:-1:2
if colInd - 1 > 0
s1 = cumulativeEnergyMap(i - 1, colInd - 1);
end
if colInd + 1 <= colNum
s2 = cumulativeEnergyMap(i - 1, colInd + 1);
end
s3 = cumulativeEnergyMap(i - 1, colInd);
if s1 < min(s2, s3)
colInd = colInd - 1;
verticalSeam(1, i - 1) = colInd;
elseif s2 < min(s1, s3)
colInd = colInd + 1;
verticalSeam(1, i - 1) = colInd;
else
verticalSeam(1, i - 1) = colInd;
end
s1 = Inf;
s2 = Inf;
s3 = Inf;
end