Why am I getting these incorrect values for the dct2 function?

6 次查看(过去 30 天)
Hello,
Basically, I'm taking the dct2 function of certain fingerprint images and then comparing them. Naturally, the image of the same person's fingers should have the lowest difference. THis is my code:
For inputting my main comparison image:
A=imread('r1.jpg');
A=imresize(A,[128,128]);
A=dct2(A);
For the image of another to be compared::
B=zeros(128,128,5);
C=imread('m1.jpg');
C=imresize(C,[128,128]);
C=dct2(C);
B(:,:,1)=C;
There are five such images. My comparison loop is:
val=999;
for i=1:5
mean2((A)-(B(:,:,i))).^2
if mean2((A)-(B(:,:,i))).^2<val
val=(mean2((A)-(B(:,:,i))).^2)
m=i
end
end
disp(m)
Now, all five pictures are from different people other than A except the fifth one.
1: 0.0186 2: 0.0037 3. 9.3263e-004 4. 0.0103 5. 0.0017
Now, the answer should be the fifth one. But due to the 3rd erratic value, it comes as 3. Why do I get such a value? What is the remedy for it? Is it the image...or the code? However, I get values such as this after comparing:
  1 个评论
Oleg Komarov
Oleg Komarov 2011-8-21
Please format the code: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099

请先登录,再进行评论。

采纳的回答

Oleg Komarov
Oleg Komarov 2011-8-21
You have to you have to square the differences not the mean:
mean2((A - B(:,:,i)).^2)
or the means of symmetric distributions (of differences) with same first central moment will be equal.
Or use imabsdiff
EDIT
vals = zeros(5,1);
for ii = 1:5
vals(ii) = mean2((A - B(:,:,ii)).^2);
end
[m,idx] = min(vals);
Calculate the differences for all images and just pinpoint the minimum.
  2 个评论
Aditya
Aditya 2011-8-21
Chief...You have no idea how thankful I am! Any other ideas on how I can improve this?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by