tic
x=[1 2;0 1];
a=imread('7.jpg');
b=imread('8.jpg');
figure
imshow(a);
figure
imshow(b);
imwrite(b,'160.jpg');
IMG={a,b};
num=size(IMG,2);
move_ht=0;
move_wd=0;
for count=1:num-1
input1=IMG{count};
input11=imresize(rgb2gray(input1),[300,200]);
input2=IMG{count+1};
input12=imresize(rgb2gray(input2),[300,200]);
F1=fft2(double(input11));
F2=fft2(double(input12));
pdm=exp(1i*(angle(F1)-angle(F2)));
cps=real(ifft2(pdm));
[i1,j1]=find(cps==max(max(cps)));
HtTrans=i1-1;
WdTrans=j1-1;
if(i1>size(input2,1)/2)
HtTrans=HtTrans-size(cps,1);
end
if(j1>size(input2,2)/2)
WdTrans=WdTrans-size(cps,2);
end
move_ht=HtTrans;
move_wd=WdTrans;
ht=move_ht;wd=move_wd;
move_ht=move_ht+ht;
move_wd=move_wd+wd;
if count==1
coimage=my_move(input11,input12,move_ht,move_wd);
else
coimage=my_move(coimage,imput12,move_ht,move_wd);
end
end
coimage1=coimage(15:size(coimage,1)-12,:);
figure
imshow(uint8(coimage));
toc
time=toc
imwrite(uint8(coimage),'161.jpg');
function coimage=my_move(input1,input2,move_ht,move_wd)
total_ht=max(size(input1,1),(abs(move_ht)+size(input2,1)));
total_wd=max(size(input1,2),(abs(move_wd)+size(input2,2)));
combImage=zeros(total_ht,total_wd);
regimg1=zeros(total_ht,total_wd);
regimg2=zeros(total_ht,total_wd);
if((move_ht>=0)&(move_wd>=0))
regimg1(1:size(input1,1),1:size(input1,2))=input1;
regimg2((1+move_ht):(move_ht+size(input2,1)),(1+move_wd):(move_wd+siz
e(input2,2)))=input2;
elseif((move_ht<0)&(move_wd<0))
regimg2(1:size(input2,1),1:size(input2,2))=input2;
regimg1((1+abs(move_ht)):(abs(move_ht)+size(input1,1)),(1+abs(move_wd
)):(abs(move_wd)+size(input1,2)))=input1;
elseif((move_ht>=0)&(move_wd<0))
regimg2((move_ht+1):(move_ht+size(input2,1)),1:size(input2,2))=input2
;
regimg1(1:size(input1,1),(abs(move_wd)+1):(abs(move_wd)+size(input1,2
)))=input1;
elseif((move_ht<0)&(move_wd>=0))
regimg1((abs(move_ht)+1):(abs(move_ht)+size(input1,1)),1:size(input1,
2))=input1;
regimg2(1:size(input2,1),(move_wd+1):(move_wd+size(input2,2)))=input2;
end
if sum(sum(regimg1==0))>sum(sum(regimg2==0))
plant=regimg1; bleed=regimg2;
else
plant=regimg2; bleed=regimg1;
end
combImage=plant;
for p=1:total_ht
for q=1:total_wd
if(combImage(p,q)==0)
combImage(p,q)=bleed(p,q);
end
end
end
function [move_ht,move_wd]=my_trans(input1,input2)
F1=fft2(input1);
F2=fft2(input2);
pdm=exp(1i*(angle(F1)-angle(F2)));
cps=real(ifft2(pdm));
[i1,j1]=find(cps==max(max(cps)));
HtTrans=i1-1;
WdTrans=j1-1;
if(i1>size(input2,1)/2)
HtTrans=HtTrans-size(cps,1);
end
if(j1>size(input2,2)/2)
WdTrans=WdTrans-size(cps,2);
end
move_ht=HtTrans;
move_wd=WdTrans;
end
x=[1 2;0 1];
a=imread('7.jpg');
b=imread('8.jpg');
figure
imshow(a);
figure
imshow(b);
imwrite(b,'160.jpg');
IMG={a,b};
num=size(IMG,2);
move_ht=0;
move_wd=0;
for count=1:num-1
input1=IMG{count};
input11=imresize(rgb2gray(input1),[300,200]);
input2=IMG{count+1};
input12=imresize(rgb2gray(input2),[300,200]);
F1=fft2(double(input11));
F2=fft2(double(input12));
pdm=exp(1i*(angle(F1)-angle(F2)));
cps=real(ifft2(pdm));
[i1,j1]=find(cps==max(max(cps)));
HtTrans=i1-1;
WdTrans=j1-1;
if(i1>size(input2,1)/2)
HtTrans=HtTrans-size(cps,1);
end
if(j1>size(input2,2)/2)
WdTrans=WdTrans-size(cps,2);
end
move_ht=HtTrans;
move_wd=WdTrans;
ht=move_ht;wd=move_wd;
move_ht=move_ht+ht;
move_wd=move_wd+wd;
if count==1
coimage=my_move(input11,input12,move_ht,move_wd);
else
coimage=my_move(coimage,imput12,move_ht,move_wd);
end
end
coimage1=coimage(15:size(coimage,1)-12,:);
figure
imshow(uint8(coimage));
toc
time=toc
imwrite(uint8(coimage),'161.jpg');
function coimage=my_move(input1,input2,move_ht,move_wd)
total_ht=max(size(input1,1),(abs(move_ht)+size(input2,1)));
total_wd=max(size(input1,2),(abs(move_wd)+size(input2,2)));
combImage=zeros(total_ht,total_wd);
regimg1=zeros(total_ht,total_wd);
regimg2=zeros(total_ht,total_wd);
if((move_ht>=0)&(move_wd>=0))
regimg1(1:size(input1,1),1:size(input1,2))=input1;
regimg2((1+move_ht):(move_ht+size(input2,1)),(1+move_wd):(move_wd+siz
e(input2,2)))=input2;
elseif((move_ht<0)&(move_wd<0))
regimg2(1:size(input2,1),1:size(input2,2))=input2;
regimg1((1+abs(move_ht)):(abs(move_ht)+size(input1,1)),(1+abs(move_wd
)):(abs(move_wd)+size(input1,2)))=input1;
elseif((move_ht>=0)&(move_wd<0))
regimg2((move_ht+1):(move_ht+size(input2,1)),1:size(input2,2))=input2
;
regimg1(1:size(input1,1),(abs(move_wd)+1):(abs(move_wd)+size(input1,2
)))=input1;
elseif((move_ht<0)&(move_wd>=0))
regimg1((abs(move_ht)+1):(abs(move_ht)+size(input1,1)),1:size(input1,
2))=input1;
regimg2(1:size(input2,1),(move_wd+1):(move_wd+size(input2,2)))=input2;
end
if sum(sum(regimg1==0))>sum(sum(regimg2==0))
plant=regimg1; bleed=regimg2;
else
plant=regimg2; bleed=regimg1;
end
combImage=plant;
for p=1:total_ht
for q=1:total_wd
if(combImage(p,q)==0)
combImage(p,q)=bleed(p,q);
end
end
end
function [move_ht,move_wd]=my_trans(input1,input2)
F1=fft2(input1);
F2=fft2(input2);
pdm=exp(1i*(angle(F1)-angle(F2)));
cps=real(ifft2(pdm));
[i1,j1]=find(cps==max(max(cps)));
HtTrans=i1-1;
WdTrans=j1-1;
if(i1>size(input2,1)/2)
HtTrans=HtTrans-size(cps,1);
end
if(j1>size(input2,2)/2)
WdTrans=WdTrans-size(cps,2);
end
move_ht=HtTrans;
move_wd=WdTrans;
end