function newImageAlign(filename)
input_Image = imread(filename);
%input_Image = imresize(input_Image,[size(input_Image,1)*sample_size/16,size(input_Image,2)*sample_size/16]);
third_of_input_size = uint16(size(input_Image,1)/3);

real_input_Image = im2double(input_Image);
real_compact_iamge(:,:,1) = real_input_Image(1:third_of_input_size,:);
real_compact_iamge(:,:,2) = real_input_Image(third_of_input_size+1:2*third_of_input_size,:);
real_compact_iamge(:,:,3) = real_input_Image(2*third_of_input_size+1:third_of_input_size*3,:);

min_NCC_1 = 0;min_NCC_2 = 0;
for x_offset = -15:15
    for y_offset = -15:15
        y_range = 10:third_of_input_size - abs(y_offset);
        x_range = 10:size(input_Image,2) - abs(x_offset);
        ground_image = real_compact_iamge(y_range,x_range,2);
        comp_image_1 = circshift(real_compact_iamge(:,:,1),[y_offset x_offset]);
        comp_image_2 = circshift(real_compact_iamge(:,:,3),[y_offset x_offset]);
        ncc1 = compute_NCC(ground_image,comp_image_1(y_range,x_range));
        if ncc1 > min_NCC_1
            min_NCC_1 = ncc1;
            max_offset_x_1 = x_offset;
            max_offset_y_1 = y_offset;
        end
         ncc2 = compute_NCC(ground_image,comp_image_2(y_range,x_range));
        if ncc2 > min_NCC_2
            min_NCC_2 = ncc2;
            max_offset_x_2 = x_offset;
            max_offset_y_2 = y_offset;
        end
    end
end
max_offset_y_1
max_offset_x_1
max_offset_y_2
max_offset_x_2
newImage2 = circshift(real_compact_iamge(:,:,1),[max_offset_y_1 max_offset_x_1]);
newImage3 = circshift(real_compact_iamge(:,:,3),[max_offset_y_2 max_offset_x_2]);
min_y_range = third_of_input_size - max(abs(max_offset_y_1),abs(max_offset_y_2)); 
min_x_range = size(input_Image,2) - max(abs(max_offset_x_1),abs(max_offset_x_2)); 
showImg = [];
showImg(:,:,1) = newImage3(1:min_y_range,1:min_x_range);
showImg(:,:,2) = real_compact_iamge(1:min_y_range,1:min_x_range,2);
showImg(:,:,3) = newImage2(1:min_y_range,1:min_x_range);
% newshowImg = rgb2hsv(showImg);
% newshowImg(:,:,2) = newshowImg(:,:,2) + 0.1;
% showImg = hsv2rgb(newshowImg);
imshow(showImg);


function ncc = compute_NCC(image_1,image_2)
image_1_col = reshape(image_1,[1,size(image_1,1)*size(image_1,2)]);
image_2_col = reshape(image_2,[1,size(image_1,1)*size(image_1,2)]);
ncc = dot(image_1_col,image_2_col) / norm(image_1_col)/norm(image_2_col);
%ncc = sum(sum((image_1-image_2)*(image_1-image_2)'));

function ssd = compute_SSD(image_1,image_2)
ssd = (image_1-image_2)*(image_1-image_2)';