Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Algorithm to find the 2 best matching images within the I images data set
- % Attempt to shorten the execution time
- function [k] = CompareHistogram(I, maxVal)
- progressbar([],0)
- tic;
- sprintf('Started searching for the 2 best images... (may take a while)')
- resultMax = 0;
- resultKey = 0;
- resultImage = 0;
- euclDistance = 0;
- maxVal=5;
- k = 0;
- % Loop through all the data images
- for i=1:1:maxVal-1
- A1 = I{i};
- HistA1=imhist(rgb2gray(A1));
- %hn1=imhist(HistA1)./numel(HistA1);
- %Reference image
- % Loop through all the other images (with index higher than i)
- %clearvars cor;
- for j=i+1:1:maxVal
- A2 = I{j}; %Image to compare with the reference image
- HistA2=imhist(rgb2gray(A2));
- euclDistance = euclDistance + pdist2(sum(sum(HistA1)),sum(sum(HistA2)));
- euclDistance
- if j=i+1
- M = euclDistance;
- k = j;
- else if euclDistance < M
- M = euclDistance;
- k = j;
- end
- % progressbar([],j/maxVal);
- end
- M
- if M > resultMax
- resultMax = M;
- resultKey = k;
- resultImage = i;
- end
- progressbar(i/(maxVal-1));
- end
- sprintf('RESULTAAT: Afbeelding %d matcht het beste met afbeelding %d corr: %s',resultImage,resultKey,num2str(resultMax))
- sprintf('Berekening duurde %s seconden',num2str(toc))
- %
- % figure('position',[200, 50, 600, 600]);
- %
- % subplot(2,1,1), imshow(I{resultImage});
- % subplot(2,1,2), imshow(I{resultKey});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement