what is wrong here?please.
2 次查看(过去 30 天)
显示 更早的评论
Hi All
i need to do matching between 2 images in matlab by following these steps:
1.Input: P1, P2 (two images).
2.Variables: Current-Matching-Ratio, Maximum-Matching-Ratio.
3.1 From: rotation = - theta; To: rotation= + theta; Step = 10 Apply rotation on P2.
3.2 From: y-translation = - ty; To: y-translation= + ty; Step = 10 Apply y-translation on P2.
3.3 From: x-translation = - tx; To: x-translation= + tx; Step = 10 Apply x-translation on P2.
3.4 Calculate Current-Matching-Ratio (the matching ratio between P1 and transformed P2)[which is no. of the overlapped white pixels between P1 and transformed P2 /no. of the white pixels in one of 2 ip image (preferably the image with the minimum count of the white pixels)].
3.5 If Current-Matching-Ratio > Maximum-Matching-Ratio Then
Maximum-Matching-Ratio = Current-Matching-Ratio Matching-Angle = rotation Matching-Y-Translation = y-translation Matching-X-Translation = x-translation
when i tried to perform this , i wrote:
tic
p0 = imread...........;
p1 = imread...........;
max_match_ratio=0;
if (nnz(p0)>nnz(p1))because i prefer to perform transformation on the image with smaller number of white pixels
p2=p1;
else
p2=p0;
end
for q=-150:10:150;
for tx=-50:10:50;
for ty=-50:10:50;
xform=[cos(q) sin(q) 0 ;-sin(q) cos(q) 0;tx ty 1];
t_form_rotate_translate=maketform('affine',xform);
cb_trans=imtransform(p2,t_form_rotate_translate);
current_matching=(sum(p2(:))&sum(cb_trans(:)))/sum(p2(:));
if (current_matching>max_match_ratio)
max_match_ratio=current_matching;
match_angle=q;
match_x_trans=tx;
match_y_trans=ty;
end
end
end
end;
time=toc;
when i implement this code ,i obtained max_match_ratio= 0.000957854406130268
i know that these images are very similar to each other ?so why this bad result ? what are the error that i did ?
help me please?
thanks
0 个评论
回答(1 个)
Image Analyst
2012-2-17
Can you give code to generate p0 and p1 from standard MATLAB demo images? Something like this:
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
p0 = grayImage < 80;
Then we can try your code. Or else upload your exact binary images to tinypic.com.
Now, your algorithm looks extremely naive. Who gave you this algorithm, where did you see it, or did you think it up yourself? Finding if a binary image is a rotated and translated version of your reference image via this method of ANDing the images and counting the overlapping pixels is not robust or reliable, and has no specificity. If you're trying to do that, you should pick a different method (like one that will work - perhaps SURF).
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!