-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrease_width.m
27 lines (22 loc) · 1023 Bytes
/
decrease_width.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
function [reducedColorImg,reducedEnergyImg] = decrease_width(im,energyImg)
cumulativeEnergyMap = cumulative_min_energy_map(energyImg,'VERTICAL');
ver_seam = find_vertical_seam(cumulativeEnergyMap);
[rowNum,colNum] = size(energyImg);
reducedColorImg(:,:,1:3) = zeros(rowNum,colNum-1,3); % initialize 3D and 2D matrix with shortter width
reducedEnergyImg = zeros(rowNum,colNum-1);
for i=1:rowNum
img_row_ch1 = im(i,:,1);
img_row_ch2 = im(i,:,2);
img_row_ch3 = im(i,:,3);
energy_row = energyImg(i,:);
remove_colInd = ver_seam(1,i);
img_row_ch1(remove_colInd)=[]; % remove the column pixel in every vector
img_row_ch2(remove_colInd)=[];
img_row_ch3(remove_colInd)=[];
energy_row(remove_colInd)=[];
reducedColorImg(i,:,1) = img_row_ch1; % update to return matrixs
reducedColorImg(i,:,2) = img_row_ch2;
reducedColorImg(i,:,3) = img_row_ch3;
reducedEnergyImg(i,:) = energy_row;
end
reducedColorImg = uint8(reducedColorImg);