Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.51 KB | None | 0 0
  1. % Algorithm to find the 2 best matching images within the I images data set
  2. % Attempt to shorten the execution time
  3. function [k] = CompareHistogram(I, maxVal)
  4. progressbar([],0)
  5. tic;
  6. sprintf('Started searching for the 2 best images... (may take a while)')
  7. resultMax = 0;
  8. resultKey = 0;
  9. resultImage = 0;
  10. euclDistance = 0;
  11. maxVal=5;
  12. k = 0;
  13.  
  14.  
  15. % Loop through all the data images
  16. for i=1:1:maxVal-1
  17.     A1 = I{i};
  18.     HistA1=imhist(rgb2gray(A1));
  19.     %hn1=imhist(HistA1)./numel(HistA1);
  20.    
  21.     %Reference image  
  22.     % Loop through all the other images (with index higher than i)
  23.     %clearvars cor;
  24.     for j=i+1:1:maxVal
  25.         A2 = I{j}; %Image to compare with the reference image
  26.         HistA2=imhist(rgb2gray(A2));
  27.        
  28.         euclDistance = euclDistance + pdist2(sum(sum(HistA1)),sum(sum(HistA2)));
  29.         euclDistance
  30.  
  31.         if j=i+1
  32.             M = euclDistance;
  33.             k = j;
  34.         else if euclDistance < M
  35.             M = euclDistance;
  36.             k = j;
  37.         end
  38. %         progressbar([],j/maxVal);
  39.     end
  40.     M
  41.     if M > resultMax
  42.         resultMax = M;
  43.         resultKey = k;
  44.         resultImage = i;
  45.     end
  46.     progressbar(i/(maxVal-1));
  47. end
  48.  
  49. sprintf('RESULTAAT: Afbeelding %d matcht het beste met afbeelding %d corr: %s',resultImage,resultKey,num2str(resultMax))
  50. sprintf('Berekening duurde %s seconden',num2str(toc))
  51. %
  52. % figure('position',[200, 50, 600, 600]);
  53. %
  54. % subplot(2,1,1), imshow(I{resultImage});
  55. % subplot(2,1,2), imshow(I{resultKey});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement