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
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
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.
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!