%% Calculate distance between grayscale images: Coins

I = imread('coins.png');
Ino=imnoise(I,'gaussian',0.1);
%Ino=imnoise(I,'salt & pepper',0.1);


figure(1)
imagesc(I)
colormap gray; axis equal off

figure(2)
imagesc(Ino)
colormap gray; axis equal off


% Caluclate distances

dE=sqrt(sum(sum((im2double(I)-im2double(Ino)).^2)))

dM=sum(sum(abs(im2double(I)-im2double(Ino))))


%% Calculate distance between RGB images: Space

I1=imread('ngc6543a.jpg');

I2=imnoise(I1,'gaussian',0.1);
%I2=imnoise(I1,'salt & pepper',0.1);


figure(3)
imshow(I1)

figure(4)
imshow(I2)

dE=sqrt(sum(sum(sum((im2double(I1)-im2double(I2)).^2))))

dM=sum(sum(sum(abs(im2double(I1)-im2double(I2)))))


%% Use image histograms to compute distances between images

I = imread('coins.png');
Ino=imnoise(I,'gaussian',0.01);
%Ino=imnoise(I,'salt & pepper',0.1);



figure(1)
count1=imhist(I);
imhist(I)
%colormap gray; axis equal off

figure(2)
count2=imhist(Ino);
imhist(Ino)
%colormap gray; axis equal off

dE=sqrt(sum((count1-count2).^2))

dM=sum(abs(count1-count2))



%% Second Example of image histograms

A=[1 0 1 0 1; ...
   0 1 0 1 0; ...
   1 0 1 0 1; ...
   0 1 0 1 0; ...
   1 0 1 0 1];

B=[0 1 0 1 0; ...
   1 0 1 0 1; ...
   0 1 0 1 0; ...
   1 0 1 0 1; ...
   0 1 0 1 0];

figure(11)
imagesc(A)
colormap gray; axis equal off

figure(12)
imagesc(B)
colormap gray; axis equal off

count1=imhist(A);
count2=imhist(B);

dE_img=sqrt(sum(sum((im2double(A)-im2double(B)).^2)))

dE_hist=sqrt(sum((count1-count2).^2))


%% Third example of image histograms

I1=imread('coins.png');
I2=I1(end:-1:1,:);

count1=imhist(I1);
count2=imhist(I2);


dE_img=sqrt(sum(sum((im2double(I1)-im2double(I2)).^2)))

dE_hist=sqrt(sum((count1-count2).^2))

