%comp 776 : assignment1
% 1.2 Prokudin-Gorskii image alignment
 close all
 pathDir='./data';
 fname='01112v.jpg';
 

im=double(imread(sprintf('%s/%s',pathDir,fname)));

[H,W,N]=size(im);

h=floor(H/3);
b=im(1:h,:,:);
g=im(h+1:2*h,:,:);
r=im(2*h+1:3*h,:,:);

maxLag=40;
 
 
  [xa,ya,xb,yb]=alignImages(r,g,b,maxLag);
 
  [g,b]=shiftImages(g,b,xa,ya,xb,yb);
  
  imColor=uint8(cat(3,r,g,b));
  figure,imshow(imColor);
%   imwrite(imColor,sprintf('%s-%s','col',fname));