%% Noisy Boxes, different sizes

image1 = rand(64,64) * 0.3;
image1(40:50, 10:20) = 1;
image2 = rand(256,256) * 0.3;
image2(10:20, 20:30) = 1;

[pos score] = stitch(image1, image2);
imshow(canvas(image1, image2, pos));

%% Noisy boxes, white sizes.
image1 = rand(256,256) * 0.3;
image1(10:20, 10:20) = 1;
image2 = rand(256,256) * 0.3;
image2(230:250, 220:240) = 1;

[pos score] = stitch(image2, image1)
imshow(canvas(image2, image1, pos))


%% Single dot test

image1 = zeros(256,256);
image2 = zeros(256,256);

image1 = image1 + rand(256, 256) * .3;
image2 = image2 + rand(256, 256) * .3;

image1(50,50) = 1;
image2(25,50) = 1;

[pos score] = stitch(image1, image2);

imshow(canvas(image1, image2, pos))

%% Single dot test

image1 = zeros(100,100);
image2 = zeros(100,100);

image1 = image1 + rand(100, 100) * .1;
image2 = image2 + rand(100, 100) * .1;

image1(50,50) = 1;
image2(90,70) = 1;

cell12 = stitch(image1, image2);
imshow(cell12)

%% 50% overlap of two em cells.

cell0 = double(imread('0001.006.png')) / 255;
cell1 = double(imread('0001.002.png')) / 255;

[pos score] = stitch(cell1, cell0);
imshow(canvas(cell1, cell0, pos));

%% 50% overlap of two em cells.

cell0 = double(imread('0001.005.png')) / 255;
cell1 = double(imread('0001.006.png')) / 255;

[pos score] = stitch(cell0, cell1);
c01 = canvas(cell0, cell1, pos);
imshow(c01)

%%

cell0 = double(imread('us2.png')) / 255;
cell1 = double(imread('us3.png')) / 255;

[pos score] = stitch(cell0, cell1);
c01 = canvas(cell0, cell1, pos);
imshow(c01)

%% Full em matching

image_list = ['0001.000.png'; '0001.001.png'; '0001.002.png'; '0001.004.png'; '0001.005.png'; '0001.006.png'];
%image_list = ['0001.004.png'; '0001.005.png'; '0001.006.png'];

out = stitch_all( image_list );
imshow(out)

%% Full us matching
image_list = ['us1.png'; 'us2.png'; 'us3.png'; 'us4.png'; 'us5.png'; 'us6.png'];
%image_list = ['us6.png'; 'us3.png'];
output = stitch_all( image_list );
imshow(output)
