Advertisement
Guest User

SimpleImagecompare

a guest
Apr 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.73 KB | None | 0 0
  1. total_images=20;
  2. ImageMatrixes=[];  
  3.  
  4.  
  5. figure(1);
  6. for i=1:total_images
  7.     str=strcat(int2str(i),'.bmp'); %creates string of photos filename
  8.     eval('img=imread(str);'); % searches current folder for photo based on string
  9.     subplot(ceil(sqrt(total_images)),ceil(sqrt(total_images)),i); %puts the image on a table based on the total images and the counter varible
  10.     imshow(img);
  11.                        
  12. end
  13.  
  14. figure(2);
  15. for i=1:total_images
  16.     edge_det = edge(img,'canny');% apply edge detection to the image
  17.     subplot(ceil(sqrt(total_images)),ceil(sqrt(total_images)),i);
  18.     imshow(edge_det);
  19.     drawnow;
  20.     [imagerow, imagecollumn]=size(edge_det);    % gets the number or rows and
  21.     temp=reshape(edge_det',imagerow*imagecollumn,1);     %creates a temporray matrix for the immage based on the size
  22.     ImageMatrixes=[ImageMatrixes, temp];         %we then insert this into our image matrix
  23. end
  24.  
  25. InputImage = input('Please enter the name of the image and its extension \n','s');
  26. InputImage = imread(strcat('C:\Users\Adam\Desktop\',InputImage)); % asks user to enter filename, combines it with desktop path
  27. InputImageMatrix = [];
  28. InputImageEdge = edge(InputImage, 'canny');
  29. [imagerowi, imagecollumni]=size(InputImage);
  30. temp=reshape(edge_det',imagerow*imagecollumn,1);
  31. InputImageMatrix = [InputImageMatrix, temp];
  32. figure(3);
  33. subplot(1,2,1);
  34. imshow(InputImage);
  35. subplot(1,2,2);
  36. imshow(InputImageEdge);
  37.  
  38. distance = [];
  39. distance2 =[];
  40. for i =1:total_images
  41.     [hd, D] = HausdorffDist(InputImageMatrix,ImageMatrixes(i));
  42.     distance = [distance, hd];
  43.     distance2 = [distance2, D];
  44. end
  45.  
  46. Numberofhs = 1:size(distance,2);
  47. subplot(1,1,1)
  48. stem(Numberofhs,distance)
  49. title('Hausdorf distance of input image','fontsize',14)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement