what is wrong here?please.

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

Réponses (1)

Image Analyst
Image Analyst le 17 Fév 2012

2 votes

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).

12 commentaires

mmm ssss
mmm ssss le 17 Fév 2012
http://www.2shared.com/photo/QSYfBUOM/0007hv1.html
http://www.2shared.com/photo/nGgWytZ1/0007hv3.html
there is a problem in downloading my images on tinypic.com,so i downloaded them to 2shared.
about this algorithm , it is called "rigid registration algorithm" , i find it in a paper with similar field, he said that it is found on a ref ,
Robert J. Schalkoff, "Pattern Recognition: Statistical, Structural and Neural Approaches", John Wiley & Sons, 1992.
i can't obtain this ref, until know i am not very understanding this algorithm ,so i tried to perform it as it was written in paper .
but the problem that i face now that i am restricted by my supervisor to implement this algorithm for comparison between my preprocessing result and the paper preprocessing result , so really , i don't now what can i do???
mmm ssss
mmm ssss le 17 Fév 2012
Also , i want some illustration about SURF, is it compare 2 image only or it can compare more than 2 images?
Image Analyst
Image Analyst le 17 Fév 2012
OK, upon supplying further context it looks like you're not doing what I thought. It looks like you may be doing this to align slices in a 3D volume where the slices may be slightly misregistered due to instrument motion or subject motion or some other reason. I'm not really up to date on the latest volume registration methods. You referenced a very old method that was perhaps state of the art 20 years ago when it was written. It may work for your purposes, but I really have my doubts if you're implementing it correctly. In fact I'd wager you're not since you haven't even read the paper ("i can't obtain this ref"). Trying nearly every possible translation and rotation to see which matches is so horribly inefficient it's not even funny! But what the hey, give it a shot. Looks like it could take a very long time to do 11*11*11 = 1331 image rotations and translations.
You can find an admittedly sparse description of SURF here: http://en.wikipedia.org/wiki/SURF, but there are additional links there. Basically it looks for salient features in the image (i.e. important landmarks) and gets the histogram of gradients around each feature to build up a feature vector. There are some fancy things in there to make it somewhat invariant to scaling, translation, and rotation, and even cropping believe it or not. Then it compares the feature vectors to find salient features in each image that "match up." I've seen impressive results from it, like taking a small image that is a cropped and rotated chunk of a larger image and finding its location in the larger parent image from which it came. Similar to SIFT if you've ever heard of that, but faster. SURF operates on one image at a time. Of course once you've done that you can compare whatever feature vectors you want. With N images there would be N*(N-1)/2 comparisons of feature vectors.
mmm ssss
mmm ssss le 18 Fév 2012
thanks for your illustration , but what do you mean by this"Trying nearly every possible translation and rotation to see which matches is so horribly inefficient it's not even funny! But what the hey, give it a shot. Looks like it could take a very long time to do 11*11*11 = 1331 image rotations and translations."
i didn't find the ref , but i wrote the steps above as they were written in the paper .
so , i really could't understand why i didn't obtain the desired result.
can i use SURF on my image in the link, or not ? are there any modification required or it can be applied directly on my images?.
Image Analyst
Image Analyst le 18 Fév 2012
Well look at your lines:
for q=-150:10:150;
for tx=-50:10:50;
for ty=-50:10:50;
doesn't that look like it's trying every single combination of q, tx, and ty? Or at least 1331 of them.
mmm ssss
mmm ssss le 18 Fév 2012
how can i write this to be correct ? any proposals?
Image Analyst
Image Analyst le 18 Fév 2012
Obtain the reference and try to code it up in MATLAB. I can't really help with that since I don't have the article either. If you want that algorithm, you'll just have to order the article.
mmm ssss
mmm ssss le 18 Fév 2012
thanks , i will try to find the error and i will post my final result.
mmm ssss
mmm ssss le 20 Fév 2012
one of my errors is :
xform=[cos(q) sin(q) 0 ;-sin(q) cos(q) 0;tx ty 1];
it must be
xform=[cos(q*pi/180) sin(qq*pi/180) 0 ;-sin(qq*pi/180) cos(qq*pi/180) 0;tx ty 1];
Walter Roberson
Walter Roberson le 20 Fév 2012
Why don't you just use sind() and cosd()
mmm ssss
mmm ssss le 20 Fév 2012
thanks in advance.this is a new information, i don't know it before.
i will use instead of sin() and cos()
mmm ssss
mmm ssss le 24 Fév 2012
hello all, i need only to inform you about this algorithm , it is not work on my images ,because of skeletonization which will affect the number of overlapped pixels and this will reduce the similarity.thank you very much to Image Analyst ,Walter Roberson.

Connectez-vous pour commenter.

Catégories

Question posée :

le 16 Fév 2012

Modifié(e) :

Jan
le 24 Oct 2013

Community Treasure Hunt

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

Start Hunting!

Translated by