-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
removeSeam.asv
66 lines (59 loc) · 1.98 KB
/
removeSeam.asv
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function newImg = removeSeam( img, seam , type )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%removeSeam function: remove given seam from the input image (img)
%Usage:
% newImg = removeSeam( img, seam );
%Input:
% -img: input image
% -seam: the interesting seam, that is extracted from getSeams function
% -type: 'H' for horizontal seams - 'V' for vertical seams
%Output:
% -newImg: new image after removing the seam
%
%Citation: Avidan, Shai, and Ariel Shamir. "Seam carving for content-aware
%image resizing. ACM Transactions on graphics (TOG). Vol. 26. No. 3.
%ACM, 2007"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Author: Mahmoud Afifi, York University.
switch lower(type)
case 'h'
newSize=[size(img,1)-1,size(img,2)];
T=0; %no transpose
case 'v'
%transpose img and seam
img_=zeros(size(img,2),size(img,1),size(img,3));
for c=1:size(img,3)
img_(:,:,c)=img(:,:,c)';
end
img=img_;
clear img_;
newSize=[size(img,1)-1,size(img,2)];
s_(1,:,2)=seam(1,:,1);
s_(1,:,1)=seam(1,:,2);
seam=s_;
clear s_;
T=1; %raise transpose flag
end
%convert indices to linear indices
linearInd=sub2ind([size(img,1),size(img,2)], seam(:,:,1), seam(:,:,2));
%get linear indicies of residual pixels
C=setdiff([1:size(img,1)*size(img,2)],linearInd);
newGray=zeros(length(C),size(img,3)); %memory allocation
newImg=zeros(newSize(1),newSize(2),size(img,3)); %memory allocation
map=zeros(newSize(1),newSize(2)); %memory allocation
for c=1:size(img,3)
gray=img(:,:,c);
gray=gray(:);
newGray(:,c)=gray(C);
newImg(:,:,c)=reshape(newGray(:,c),newSize);
end
if T==1
img_=zeros(size(newImg,2),size(newImg,1),size(newImg,3));
for c=1:size(img,3)
img_(:,:,c)=newImg(:,:,c)';
end
newImg=img_;
clear img_;
end
newImg=uint8(newImg);
end