%--------------------------------------------------------------------------
%----------------- EE 363 / PSYCH 221 Winter 2007--------------------------
%--------------------------------------------------------------------------
%NAME:   Athanasios Bismpigiannis
%DEPARTMENT: Electrical Engineering
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------

%reading the distorted image
imfile=input('What is the name of the image file that you want to measure the distortion?\n','s');
im1=imread(imfile);
im=im1(:,:,1);
im(find(im<100))=0;
im(find(im>100))=1;

%reading the origial image
imfile=input('What is the name of the image file that has no distortion?\n','s');
im1=imread(imfile);
im_no=im1(:,:,1);
im_no(find(im_no<100))=0;
im_no(find(im_no>100))=1;

%asking for the number of points to be used for the distortion measurements
num_of_points=input('How many points you want to use in order to measure the distortion?\n')
%using the mouse give thepoints on the images
imshow(im,[0 1]);
[x y]=ginput(num_of_points);
imshow(im_no,[0 1]);
[x_no y_no]=ginput(num_of_points);

x_dis=abs(x-x_no);
y_dis=abs(y-y_no);

%this is the mean square transfer that is applied to a point.
dist = sum(sqrt(x_dis.^2 + y_dis.^2))/(length(x_dis));