Matching an image with a database

조회 수: 17 (최근 30일)
Shizuka
Shizuka 2013년 3월 16일
댓글: Hamad ALshahrani 2020년 3월 30일
I am looking to compare a new image to a database of images, and then output the higher "similarity". The images I want to compare are similar, but the problem is though because they're not pixel by pixel equal. I've tried to use BoW (Bag Of Words) model already, as per recommendation, I tried various implementations without success, the best correct rate I got was 30%, which is something really low.
Let me show you what I am talking about: (imgur gallery with 5 example images) http://imgur.com/a/ukf5E#0. I want to detect that the four initial images are equal, and the fifth one is different. I wouldn't mind only detecting that the ones with the same angle orientation are equal, though. (In my example 2, 3 and 4)
So, that being said, are there any better methods than BoW for that? Or perhaps BoW should be enough if I implemented in a different way?
Thanks in advance.
  댓글 수: 2
Aravind Dhakshinamoorthy
Aravind Dhakshinamoorthy 2016년 12월 14일
Try using the SIFT algorithm. It detects key points in both images and maps the similar ones. Greater number of similar points greater the similarity.
Hamad ALshahrani
Hamad ALshahrani 2020년 3월 30일
Write a Matlab program to find an image in the database similar to a query image which it is: a. Not in the database but for the same person. b. Not in the database and for another person. For both cases above, repeat the process 10 times on different faces and compute the accuracy ratio.

댓글을 달려면 로그인하십시오.

채택된 답변

Anand
Anand 2013년 3월 18일
BoF seems like a reasonable approach to this problem. Usually, you are working with a much larger set of images than just 5. Crucial to BoF are the feature points and descriptors you use to represent the images as well as the size of the visual vocabulary.
In the example below, I have used SURF features to detect feature points and extract sparse descriptors. I used SURF because they are scale and rotation-invariant. The Computer Vision System Toolbox has functions that enable you to do this:
I then used the K-means algorithm to construct a visual vocabulary using 20 words. This function is part of the Statistics Toolbox. After creating a visual vocabulary, I created a bag-of-features representation for each image using this visual vocabulary. We now have a feature vector of length 20 for each of the 5 images. Applying K-means (again) on this to partition it into 2 sets gives the desired result. The fist four images are partitioned into 1 set and the last image to a different set.
%%Read images
im{1} = rgb2gray(imread('http://i.imgur.com/TMyflBl.png'));
im{2} = rgb2gray(imread('http://i.imgur.com/ozygW2g.png'));
im{3} = rgb2gray(imread('http://i.imgur.com/dGj8FNE.png'));
im{4} = rgb2gray(imread('http://i.imgur.com/VbTLPjG.png'));
im{5} = rgb2gray(imread('http://i.imgur.com/huj2El9.png'));
%%Detect and extract MSER features
detectFeatures = @(in) {detectSURFFeatures(in)};
regions = cellfun(detectFeatures,im);
extractAndTransposeFeatures = @(in,pts) extractFeatures(in,pts)';
features = cellfun(extractAndTransposeFeatures,im,regions,'UniformOutput',false);
figure;
for i = 1 : 5
subplot(2,3,i);
imshow(im{i});
hold on;
plot(regions{i});
end
%%Create a visual vocabulary with 20 words
nWords = 20;
%use kmeans for constructing the vocabulary.
[idx,centers] = kmeans([features{:}]',nWords);
%%BoF Feature Representation
histFtrs = cell(5,1);
for i = 1 : 5
start = 1;
histFtrs{i} = hist(idx(start:start+size(features{i},2)),nWords)';
%normalize
histFtrs{i} = histFtrs{i}./sum(hisFtrs{i});
end
%display histograms
figure;
for i = 1 : 5;
subplot(2,3,i);
bar(histFtrs{i});
end
%%Partition images into 2 sets using kmeans
idx = kmeans([histFtrs{:}]',2)
% idx =
%
% 2
% 2
% 2
% 2
% 1
Hope this helps. Bear in mind that you may need to do a lot more fiddling with some of the parameters and general approach for a more complicated problem.
  댓글 수: 3
Emmanuel Oreoluwa
Emmanuel Oreoluwa 2014년 10월 20일
Hi Anand, Thanks for your clear explanation. Just want to ask if the coordinates of the centers which is 20x64 is for a single image or for the five images?
Mohammad Mortazavi
Mohammad Mortazavi 2016년 5월 10일
편집: Mohammad Mortazavi 2016년 5월 10일
hi! i think your code is little wrong. in below section:
for i = 1 : 5
start = 1;
histFtrs{i} = hist(idx(start:start+size(features{i},2)),nWords)';
%normalize
histFtrs{i} = histFtrs{i}./sum(hisFtrs{i});
end
always (start=1) in all rounds of loop!!! and it counts from begin for all images. i think you should change this code to:
start = 1;
for i = 1 : k
histFtrs{i} = hist(idx(start:start+size(features{i},2)-1),nWords)';
%normalize
histFtrs{i} = histFtrs{i}./sum(histFtrs{i});
start = start+size(features{i},2);
end
now we can count all parts for all images!
i run your code, but my result is different.
my idx=
1
2
2
1
1

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Anand
Anand 2013년 3월 23일
save idx.mat idx;
save centers.mat centers;

Mohammed Magdy
Mohammed Magdy 2013년 10월 7일
hello please why did you use this number (2) here (features{i},2)
histFtrs{i} = hist(idx(start:start+size(features{i},2)),nWords)';
  댓글 수: 5
Anand
Anand 2014년 3월 12일
hamed abdulaziz
hamed abdulaziz 2014년 3월 23일
Anand :Thank you,I saw the code above but I divided each image to patches(blocks) and extracted local features from each patch,where is the code doesn't do that,could you guide me with my thanks.

댓글을 달려면 로그인하십시오.


Yuva
Yuva 2017년 10월 20일
I am doing my final year project on attedance system by face recognition using SIFT algorithm,if there is any code on this project please comment code or provide any link .

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by