http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141
MATLAB Central Newsreader  Image rotation detection probelm
Feed for thread: Image rotation detection probelm
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 19 Jun 2009 09:50:19 +0000
Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#658707
Pradyumna A
Hello,<br>
<br>
I have 2 images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the 2nd image is rotated wrt 1st one. Also in future, the second image will be scaled and translated along with this rotation !. This has to be done automatically (without human interference in selecting feature points etc)<br>
<br>
Now to do this I am using Fourier Mellin transform. But this is not accurate and dosent work for all angles :(. Is there any other means to achive this task ?<br>
<br>
Is there a Fourier Mellin transform readily implemented on Matlab ?<br>
<br>
Thanks in advance,<br>
Ayyala

Fri, 19 Jun 2009 14:49:03 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#658782
Matt
"Pradyumna A" <a_pradyumna@yahoo.com> wrote in message <h1fn0q$aeg$1@fred.mathworks.com>...<br>
> Hello,<br>
> <br>
> I have 2 images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the 2nd image is rotated wrt 1st one. Also in future, the second image will be scaled <br>
<br>
<br>
In what way will the image be scaled? Do you mean stretched geometrically or do you mean all the pixel values will be scaled?<br>
<br>
<br>
>and translated along with this rotation !. This has to be done automatically (without human interference in selecting feature points etc)<br>
<br>
<br>
One thing you can try is to compute<br>
<br>
P1=abs(fft(radon(Image1)))<br>
P2=abs(fft(radon(Image2)))<br>
<br>
You will see that P1 is shifted with respect to P2 by an amount corresponding to the rotation. You can use your favorite shift measurement technique (e.g. correlation) to calculate the shift, and hence the rotation. Also, translation will not affect P1 and P2.

Wed, 16 Sep 2009 07:50:02 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#680453
YuanLiang Tang
Matt:<br>
The code you provided is really good. What I did is to further sum the columns of P1 and P2 and perform crosscorrelation to find the angle of rotation. To be more specific,<br>
<br>
%%%%%%%%%%%%%%%%<br>
P1=abs(fft(radon(Image1)));<br>
P2=abs(fft(radon(Image2)));<br>
a = sum(P1);<br>
b = sum(P2);<br>
a = amean(a);<br>
b = bmean(b);<br>
[m n] = max(xcorr(a, b));<br>
angle = length(a)n+1 % The angle of rotation<br>
%%%%%%%%%%%%%%%%<br>
<br>
The code above worked just fine. However, what is the purpose of "fft" after radon transform? Can we skip the "fft" part? Thanks.<br>
<br>
Y.L. Tang<br>
<br>
<br>
"Matt " <xys@whatever.com> wrote in message <h1g8gu$mrc$1@fred.mathworks.com>...<br>
> "Pradyumna A" <a_pradyumna@yahoo.com> wrote in message <h1fn0q$aeg$1@fred.mathworks.com>...<br>
> > Hello,<br>
> > <br>
> > I have 2 images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the 2nd image is rotated wrt 1st one. Also in future, the second image will be scaled <br>
> <br>
> <br>
> In what way will the image be scaled? Do you mean stretched geometrically or do you mean all the pixel values will be scaled?<br>
> <br>
> <br>
> >and translated along with this rotation !. This has to be done automatically (without human interference in selecting feature points etc)<br>
> <br>
> <br>
> One thing you can try is to compute<br>
> <br>
> P1=abs(fft(radon(Image1)))<br>
> P2=abs(fft(radon(Image2)))<br>
> <br>
> You will see that P1 is shifted with respect to P2 by an amount corresponding to the rotation. You can use your favorite shift measurement technique (e.g. correlation) to calculate the shift, and hence the rotation. Also, translation will not affect P1 and P2.

Tue, 03 Aug 2010 00:45:06 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#767912
Phillip
I stumbled across this while trying to solve the same problem (determine rotation between 2 images). Thanks to those who posted here. You should only need the radon projection along one angle for one of the images. Also, the use of the FFT confused me so I have used it at the end to do the correlation in a more familiar way to me. Code snippet:<br>
<br>
thetas = [45 : 45]; % Enter desired range<br>
<br>
P1 = radon(Image1,0); % Only 1 projection is needed for reference image<br>
P2 = radon(Image2,thetas); % All projections to be considered for the other image<br>
<br>
% Compare the projections for Image2 to the projection for Image1 using cross <br>
% correlation. The most correlated projection gives the amount of image rotation.<br>
<br>
for ii = 1:length(thetas)<br>
b = P2(:,ii);<br>
this_correlation = abs(ifft(P1.*conj(b)));<br>
angle_scores(ii) = max(max(this_correlation));<br>
end<br>
<br>
<br>
<br>
"YuanLiang Tang" <john.doe.nospam@example.com> wrote in message <h8q5ba$fds$1@fred.mathworks.com>...<br>
> Matt:<br>
> The code you provided is really good. What I did is to further sum the columns of P1 and P2 and perform crosscorrelation to find the angle of rotation. To be more specific,<br>
> <br>
> %%%%%%%%%%%%%%%%<br>
> P1=abs(fft(radon(Image1)));<br>
> P2=abs(fft(radon(Image2)));<br>
> a = sum(P1);<br>
> b = sum(P2);<br>
> a = amean(a);<br>
> b = bmean(b);<br>
> [m n] = max(xcorr(a, b));<br>
> angle = length(a)n+1 % The angle of rotation<br>
> %%%%%%%%%%%%%%%%<br>
> <br>
> The code above worked just fine. However, what is the purpose of "fft" after radon transform? Can we skip the "fft" part? Thanks.<br>
> <br>
> Y.L. Tang<br>
> <br>
> <br>
> "Matt " <xys@whatever.com> wrote in message <h1g8gu$mrc$1@fred.mathworks.com>...<br>
> > "Pradyumna A" <a_pradyumna@yahoo.com> wrote in message <h1fn0q$aeg$1@fred.mathworks.com>...<br>
> > > Hello,<br>
> > > <br>
> > > I have 2 images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the 2nd image is rotated wrt 1st one. Also in future, the second image will be scaled <br>
> > <br>
> > <br>
> > In what way will the image be scaled? Do you mean stretched geometrically or do you mean all the pixel values will be scaled?<br>
> > <br>
> > <br>
> > >and translated along with this rotation !. This has to be done automatically (without human interference in selecting feature points etc)<br>
> > <br>
> > <br>
> > One thing you can try is to compute<br>
> > <br>
> > P1=abs(fft(radon(Image1)))<br>
> > P2=abs(fft(radon(Image2)))<br>
> > <br>
> > You will see that P1 is shifted with respect to P2 by an amount corresponding to the rotation. You can use your favorite shift measurement technique (e.g. correlation) to calculate the shift, and hence the rotation. Also, translation will not affect P1 and P2.

Tue, 21 Dec 2010 19:32:05 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#806605
blue ice
"Phillip" wrote in message <i37oqi$p65$1@fred.mathworks.com>...<br>
> I stumbled across this while trying to solve the same problem (determine rotation between 2 images). Thanks to those who posted here. You should only need the radon projection along one angle for one of the images. Also, the use of the FFT confused me so I have used it at the end to do the correlation in a more familiar way to me. Code snippet:<br>
> <br>
> thetas = [45 : 45]; % Enter desired range<br>
> <br>
> P1 = radon(Image1,0); % Only 1 projection is needed for reference image<br>
> P2 = radon(Image2,thetas); % All projections to be considered for the other image<br>
> <br>
> % Compare the projections for Image2 to the projection for Image1 using cross <br>
> % correlation. The most correlated projection gives the amount of image rotation.<br>
> <br>
<br>
while trying this code i got this error....can you tell me WHY ?????<br>
<br>
??? Error using ==> times<br>
Matrix dimensions must agree.<br>
<br>
> for ii = 1:length(thetas)<br>
> b = P2(:,ii);<br>
> this_correlation = abs(ifft(P1.*conj(b)));<br>
> angle_scores(ii) = max(max(this_correlation));<br>
> end<br>
> <br>
> <br>
> <br>
> "YuanLiang Tang" <john.doe.nospam@example.com> wrote in message <h8q5ba$fds$1@fred.mathworks.com>...<br>
> > Matt:<br>
> > The code you provided is really good. What I did is to further sum the columns of P1 and P2 and perform crosscorrelation to find the angle of rotation. To be more specific,<br>
> > <br>
> > %%%%%%%%%%%%%%%%<br>
> > P1=abs(fft(radon(Image1)));<br>
> > P2=abs(fft(radon(Image2)));<br>
> > a = sum(P1);<br>
> > b = sum(P2);<br>
> > a = amean(a);<br>
> > b = bmean(b);<br>
> > [m n] = max(xcorr(a, b));<br>
> > angle = length(a)n+1 % The angle of rotation<br>
> > %%%%%%%%%%%%%%%%<br>
> > <br>
> > The code above worked just fine. However, what is the purpose of "fft" after radon transform? Can we skip the "fft" part? Thanks.<br>
> > <br>
> > Y.L. Tang<br>
> > <br>
> > <br>
> > "Matt " <xys@whatever.com> wrote in message <h1g8gu$mrc$1@fred.mathworks.com>...<br>
> > > "Pradyumna A" <a_pradyumna@yahoo.com> wrote in message <h1fn0q$aeg$1@fred.mathworks.com>...<br>
> > > > Hello,<br>
> > > > <br>
> > > > I have 2 images. One is the reference image and the other is the rotated version of the reference image. I would like to find what is the angle by which the 2nd image is rotated wrt 1st one. Also in future, the second image will be scaled <br>
> > > <br>
> > > <br>
> > > In what way will the image be scaled? Do you mean stretched geometrically or do you mean all the pixel values will be scaled?<br>
> > > <br>
> > > <br>
> > > >and translated along with this rotation !. This has to be done automatically (without human interference in selecting feature points etc)<br>
> > > <br>
> > > <br>
> > > One thing you can try is to compute<br>
> > > <br>
> > > P1=abs(fft(radon(Image1)))<br>
> > > P2=abs(fft(radon(Image2)))<br>
> > > <br>
> > > You will see that P1 is shifted with respect to P2 by an amount corresponding to the rotation. You can use your favorite shift measurement technique (e.g. correlation) to calculate the shift, and hence the rotation. Also, translation will not affect P1 and P2.

Tue, 21 Dec 2010 22:56:04 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#806671
Phillip
> while trying this code i got this error....can you tell me WHY ?????<br>
> <br>
> ??? Error using ==> times<br>
> Matrix dimensions must agree.<br>
> <br>
> > for ii = 1:length(thetas)<br>
> > b = P2(:,ii);<br>
> > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > angle_scores(ii) = max(max(this_correlation));<br>
> > end<br>
<br>
Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
<br>
However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
<br>
1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
<br>
2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
<br>
I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
I got a Matlab function for creating a polar transform from this page:<br>
<br>
<a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
<br>
This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
<br>
Hope this approach is useful to others.

Tue, 21 Dec 2010 23:14:05 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#806678
Matt J
"Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
><br>
> <br>
> 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
=====<br>
<br>
Why not just increase the number of projection angles used for the reference image, so as to decrease the SNR?

Wed, 22 Dec 2010 01:02:05 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#806702
Phillip
"Matt J" wrote in message <iercbt$rf9$1@fred.mathworks.com>...<br>
> "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> ><br>
> > <br>
> > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> =====<br>
> <br>
> Why not just increase the number of projection angles used for the reference image, so as to decrease the SNR? <br>
<br>
I did try that when I started having issues. I didn't have much luck with it; I'm not sure why but it's probably because the angles of rotation are so small in my data. I could probably upsample the images to make this work better, but my images are quite large and I frequently have memory issues in Matlab. I liked the polar transform approach better because I was able to upsample in just the one dimension.

Wed, 14 Nov 2012 13:34:13 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#891671
Darren g
Hi Phillip,<br>
I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
Any help would be much appreciated.<br>
Thanks.<br>
Darren<br>
<br>
"Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > while trying this code i got this error....can you tell me WHY ?????<br>
> > <br>
> > ??? Error using ==> times<br>
> > Matrix dimensions must agree.<br>
> > <br>
> > > for ii = 1:length(thetas)<br>
> > > b = P2(:,ii);<br>
> > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > angle_scores(ii) = max(max(this_correlation));<br>
> > > end<br>
> <br>
> Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> <br>
> However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> <br>
> 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> <br>
> 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> <br>
> I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> I got a Matlab function for creating a polar transform from this page:<br>
> <br>
> <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> <br>
> This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> <br>
> Hope this approach is useful to others.

Thu, 15 Nov 2012 04:17:05 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#891718
Phillip
Hi Darren,<br>
<br>
From the link I gave above, I used the "polartrans.m" file.<br>
<br>
Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
<br>
If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
<br>
NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
<br>
"Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> Any help would be much appreciated.<br>
> Thanks.<br>
> Darren<br>
> <br>
> "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > <br>
> > > ??? Error using ==> times<br>
> > > Matrix dimensions must agree.<br>
> > > <br>
> > > > for ii = 1:length(thetas)<br>
> > > > b = P2(:,ii);<br>
> > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > end<br>
> > <br>
> > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > <br>
> > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > <br>
> > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > <br>
> > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > <br>
> > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > I got a Matlab function for creating a polar transform from this page:<br>
> > <br>
> > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > <br>
> > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > <br>
> > Hope this approach is useful to others.

Mon, 19 Nov 2012 18:43:13 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892004
Darren g
Hi Phillip,<br>
<br>
Thanks for the detailed information. I am not an expert in matlab but currently learning for this image rotation measurement. I have tried the polartrans.m function. But, when calling this function what values I need to supply within the code. I tried nrad=256 and ntheta=360, are the width of my image and a full range of theta. My understanding is that the other parameters cx, cy, linlog, shape should take some default values but when running the code it show error "??? Undefined function or variable 'cx'". Here is the code I tried for polar transform.<br>
<br>
a=1;<br>
image = strcat('',num2str(a,'%04d'),'.png');<br>
im = imread(image);<br>
figure(1);<br>
imagesc(im);<br>
axis image;<br>
nrad = 256; ntheta = 360;<br>
pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape);<br>
figure(2);<br>
imagesc(pim);title('Polar transform of image');<br>
axis image;<br>
<br>
Any error in this code?<br>
<br>
Thanks in advance.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <k81qc1$app$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> From the link I gave above, I used the "polartrans.m" file.<br>
> <br>
> Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
> <br>
> If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
> <br>
> NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
> <br>
> "Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> > Any help would be much appreciated.<br>
> > Thanks.<br>
> > Darren<br>
> > <br>
> > "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > > <br>
> > > > ??? Error using ==> times<br>
> > > > Matrix dimensions must agree.<br>
> > > > <br>
> > > > > for ii = 1:length(thetas)<br>
> > > > > b = P2(:,ii);<br>
> > > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > > end<br>
> > > <br>
> > > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > > <br>
> > > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > > <br>
> > > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > > <br>
> > > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > > <br>
> > > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > > I got a Matlab function for creating a polar transform from this page:<br>
> > > <br>
> > > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > > <br>
> > > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > > <br>
> > > Hope this approach is useful to others.

Tue, 20 Nov 2012 01:24:14 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892020
Phillip
Hi Darren,<br>
<br>
When you have optional arguments like that, you have to omit them if you don't want to use them. Otherwise the function thinks you are trying to specify them, but because you haven't defined cx, cy, linlog, shape it gives an error. i.e. you need to change the call to polartrans to:<br>
<br>
pim = polartrans(im, nrad, ntheta);<br>
<br>
<br>
"Darren g" wrote in message <k8duk1$kjn$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> Thanks for the detailed information. I am not an expert in matlab but currently learning for this image rotation measurement. I have tried the polartrans.m function. But, when calling this function what values I need to supply within the code. I tried nrad=256 and ntheta=360, are the width of my image and a full range of theta. My understanding is that the other parameters cx, cy, linlog, shape should take some default values but when running the code it show error "??? Undefined function or variable 'cx'". Here is the code I tried for polar transform.<br>
> <br>
> a=1;<br>
> image = strcat('',num2str(a,'%04d'),'.png');<br>
> im = imread(image);<br>
> figure(1);<br>
> imagesc(im);<br>
> axis image;<br>
> nrad = 256; ntheta = 360;<br>
> pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape);<br>
> figure(2);<br>
> imagesc(pim);title('Polar transform of image');<br>
> axis image;<br>
> <br>
> Any error in this code?<br>
> <br>
> Thanks in advance.<br>
> Darren<br>
> <br>
> <br>
> "Phillip" wrote in message <k81qc1$app$1@newscl01ah.mathworks.com>...<br>
> > Hi Darren,<br>
> > <br>
> > From the link I gave above, I used the "polartrans.m" file.<br>
> > <br>
> > Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
> > <br>
> > If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
> > <br>
> > NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
> > <br>
> > "Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> > > Hi Phillip,<br>
> > > I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> > > Any help would be much appreciated.<br>
> > > Thanks.<br>
> > > Darren<br>
> > > <br>
> > > "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > > > <br>
> > > > > ??? Error using ==> times<br>
> > > > > Matrix dimensions must agree.<br>
> > > > > <br>
> > > > > > for ii = 1:length(thetas)<br>
> > > > > > b = P2(:,ii);<br>
> > > > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > > > end<br>
> > > > <br>
> > > > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > > > <br>
> > > > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > > > <br>
> > > > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > > > <br>
> > > > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > > > <br>
> > > > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > > > I got a Matlab function for creating a polar transform from this page:<br>
> > > > <br>
> > > > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > > > <br>
> > > > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > > > <br>
> > > > Hope this approach is useful to others.

Tue, 20 Nov 2012 22:32:13 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892085
Darren g
Hi Phillip,<br>
<br>
Many thanks. Yes. It is now working with your suggession. The problem I have encountered with those optional arguments is that I tried without quote as below<br>
pim = polartrans(im, nrad, ntheta,cx,cy, log, valid);<br>
<br>
Now it is working with quote for the 'log' and 'valid' as below.<br>
pim = polartrans(im, nrad, ntheta,cx,cy, 'log', 'valid');<br>
So far got to work up to transforming the two images to polatranform and can clearly see a shift on the two transformed images.<br>
I have not understand the xcorre2 for crosscorrelation that you mentioned earlier and the multiplication to calculate the angle of rotation and would appreciate any suggestion or part of the code if you can remember now.<br>
<br>
Thanks.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <k8em3u$eut$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> When you have optional arguments like that, you have to omit them if you don't want to use them. Otherwise the function thinks you are trying to specify them, but because you haven't defined cx, cy, linlog, shape it gives an error. i.e. you need to change the call to polartrans to:<br>
> <br>
> pim = polartrans(im, nrad, ntheta);<br>
> <br>
> <br>
> "Darren g" wrote in message <k8duk1$kjn$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > Thanks for the detailed information. I am not an expert in matlab but currently learning for this image rotation measurement. I have tried the polartrans.m function. But, when calling this function what values I need to supply within the code. I tried nrad=256 and ntheta=360, are the width of my image and a full range of theta. My understanding is that the other parameters cx, cy, linlog, shape should take some default values but when running the code it show error "??? Undefined function or variable 'cx'". Here is the code I tried for polar transform.<br>
> > <br>
> > a=1;<br>
> > image = strcat('',num2str(a,'%04d'),'.png');<br>
> > im = imread(image);<br>
> > figure(1);<br>
> > imagesc(im);<br>
> > axis image;<br>
> > nrad = 256; ntheta = 360;<br>
> > pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape);<br>
> > figure(2);<br>
> > imagesc(pim);title('Polar transform of image');<br>
> > axis image;<br>
> > <br>
> > Any error in this code?<br>
> > <br>
> > Thanks in advance.<br>
> > Darren<br>
> > <br>
> > <br>
> > "Phillip" wrote in message <k81qc1$app$1@newscl01ah.mathworks.com>...<br>
> > > Hi Darren,<br>
> > > <br>
> > > From the link I gave above, I used the "polartrans.m" file.<br>
> > > <br>
> > > Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
> > > <br>
> > > If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
> > > <br>
> > > NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
> > > <br>
> > > "Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> > > > Hi Phillip,<br>
> > > > I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> > > > Any help would be much appreciated.<br>
> > > > Thanks.<br>
> > > > Darren<br>
> > > > <br>
> > > > "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > > > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > > > > <br>
> > > > > > ??? Error using ==> times<br>
> > > > > > Matrix dimensions must agree.<br>
> > > > > > <br>
> > > > > > > for ii = 1:length(thetas)<br>
> > > > > > > b = P2(:,ii);<br>
> > > > > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > > > > end<br>
> > > > > <br>
> > > > > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > > > > <br>
> > > > > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > > > > <br>
> > > > > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > > > > <br>
> > > > > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > > > > <br>
> > > > > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > > > > I got a Matlab function for creating a polar transform from this page:<br>
> > > > > <br>
> > > > > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > > > > <br>
> > > > > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > > > > <br>
> > > > > Hope this approach is useful to others.

Wed, 21 Nov 2012 04:00:23 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892091
Phillip
Hi Darren,<br>
<br>
Try something like<br>
<br>
correlationMatrix = xcorr2(image1,image2);<br>
figure; imagesc(correlationMatrix)<br>
<br>
You will see a bright patch on a dark background. If the 2 input images were the same, the patch would be centered in the array. If the 2 input images are displaced relative to each other, the bright patch will be displaced by that amount. To quantify the amount, you can start with:<br>
<br>
[~,maxColumn] = max(max(correlationMatrix));<br>
[~,maxRow] = max(correlationMatrix(:,maxColumn));<br>
<br>
This will tell you the column and row that the brightest point of the image was found in. You can then compare this to the (half) size of the whole array to quantify the displacement.<br>
<br>
If you want a more precise (subpixel) estimate of the displacement, you can look into calculating the centre of mass of the bright patch instead of just finding the peak.<br>
<br>
"Darren g" wrote in message <k8h0dd$4uj$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> Many thanks. Yes. It is now working with your suggession. The problem I have encountered with those optional arguments is that I tried without quote as below<br>
> pim = polartrans(im, nrad, ntheta,cx,cy, log, valid);<br>
> <br>
> Now it is working with quote for the 'log' and 'valid' as below.<br>
> pim = polartrans(im, nrad, ntheta,cx,cy, 'log', 'valid');<br>
> So far got to work up to transforming the two images to polatranform and can clearly see a shift on the two transformed images.<br>
> I have not understand the xcorre2 for crosscorrelation that you mentioned earlier and the multiplication to calculate the angle of rotation and would appreciate any suggestion or part of the code if you can remember now.<br>
> <br>
> Thanks.<br>
> Darren<br>
> <br>
> <br>
> "Phillip" wrote in message <k8em3u$eut$1@newscl01ah.mathworks.com>...<br>
> > Hi Darren,<br>
> > <br>
> > When you have optional arguments like that, you have to omit them if you don't want to use them. Otherwise the function thinks you are trying to specify them, but because you haven't defined cx, cy, linlog, shape it gives an error. i.e. you need to change the call to polartrans to:<br>
> > <br>
> > pim = polartrans(im, nrad, ntheta);<br>
> > <br>
> > <br>
> > "Darren g" wrote in message <k8duk1$kjn$1@newscl01ah.mathworks.com>...<br>
> > > Hi Phillip,<br>
> > > <br>
> > > Thanks for the detailed information. I am not an expert in matlab but currently learning for this image rotation measurement. I have tried the polartrans.m function. But, when calling this function what values I need to supply within the code. I tried nrad=256 and ntheta=360, are the width of my image and a full range of theta. My understanding is that the other parameters cx, cy, linlog, shape should take some default values but when running the code it show error "??? Undefined function or variable 'cx'". Here is the code I tried for polar transform.<br>
> > > <br>
> > > a=1;<br>
> > > image = strcat('',num2str(a,'%04d'),'.png');<br>
> > > im = imread(image);<br>
> > > figure(1);<br>
> > > imagesc(im);<br>
> > > axis image;<br>
> > > nrad = 256; ntheta = 360;<br>
> > > pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape);<br>
> > > figure(2);<br>
> > > imagesc(pim);title('Polar transform of image');<br>
> > > axis image;<br>
> > > <br>
> > > Any error in this code?<br>
> > > <br>
> > > Thanks in advance.<br>
> > > Darren<br>
> > > <br>
> > > <br>
> > > "Phillip" wrote in message <k81qc1$app$1@newscl01ah.mathworks.com>...<br>
> > > > Hi Darren,<br>
> > > > <br>
> > > > From the link I gave above, I used the "polartrans.m" file.<br>
> > > > <br>
> > > > Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
> > > > <br>
> > > > If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
> > > > <br>
> > > > NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
> > > > <br>
> > > > "Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> > > > > Hi Phillip,<br>
> > > > > I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> > > > > Any help would be much appreciated.<br>
> > > > > Thanks.<br>
> > > > > Darren<br>
> > > > > <br>
> > > > > "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > > > > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > > > > > <br>
> > > > > > > ??? Error using ==> times<br>
> > > > > > > Matrix dimensions must agree.<br>
> > > > > > > <br>
> > > > > > > > for ii = 1:length(thetas)<br>
> > > > > > > > b = P2(:,ii);<br>
> > > > > > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > > > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > > > > > end<br>
> > > > > > <br>
> > > > > > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > > > > > <br>
> > > > > > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > > > > > <br>
> > > > > > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > > > > > <br>
> > > > > > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > > > > > <br>
> > > > > > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > > > > > I got a Matlab function for creating a polar transform from this page:<br>
> > > > > > <br>
> > > > > > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > > > > > <br>
> > > > > > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > > > > > <br>
> > > > > > Hope this approach is useful to others.

Mon, 26 Nov 2012 06:38:12 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892396
Darren g
Hi Phillip,<br>
<br>
Many thanks. Yes. My code is now working after adopting your suggestion for finding the column and row in which the maximum peak intensity is found. For finding the centre of mass of the image to measure the angle of rotation smaller than one degree I am trying the regionprobs but not yet found a way on how to integrate this within my code. Is this the one you mentioned for finding to centre of mass or any other easy way of doing? Your help for this is much appreciated. <br>
<br>
Darren <br>
<br>
"Phillip" wrote in message <k8hjkn$69s$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> Try something like<br>
> <br>
> correlationMatrix = xcorr2(image1,image2);<br>
> figure; imagesc(correlationMatrix)<br>
> <br>
> You will see a bright patch on a dark background. If the 2 input images were the same, the patch would be centered in the array. If the 2 input images are displaced relative to each other, the bright patch will be displaced by that amount. To quantify the amount, you can start with:<br>
> <br>
> [~,maxColumn] = max(max(correlationMatrix));<br>
> [~,maxRow] = max(correlationMatrix(:,maxColumn));<br>
> <br>
> This will tell you the column and row that the brightest point of the image was found in. You can then compare this to the (half) size of the whole array to quantify the displacement.<br>
> <br>
> If you want a more precise (subpixel) estimate of the displacement, you can look into calculating the centre of mass of the bright patch instead of just finding the peak.<br>
> <br>
> "Darren g" wrote in message <k8h0dd$4uj$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > Many thanks. Yes. It is now working with your suggession. The problem I have encountered with those optional arguments is that I tried without quote as below<br>
> > pim = polartrans(im, nrad, ntheta,cx,cy, log, valid);<br>
> > <br>
> > Now it is working with quote for the 'log' and 'valid' as below.<br>
> > pim = polartrans(im, nrad, ntheta,cx,cy, 'log', 'valid');<br>
> > So far got to work up to transforming the two images to polatranform and can clearly see a shift on the two transformed images.<br>
> > I have not understand the xcorre2 for crosscorrelation that you mentioned earlier and the multiplication to calculate the angle of rotation and would appreciate any suggestion or part of the code if you can remember now.<br>
> > <br>
> > Thanks.<br>
> > Darren<br>
> > <br>
> > <br>
> > "Phillip" wrote in message <k8em3u$eut$1@newscl01ah.mathworks.com>...<br>
> > > Hi Darren,<br>
> > > <br>
> > > When you have optional arguments like that, you have to omit them if you don't want to use them. Otherwise the function thinks you are trying to specify them, but because you haven't defined cx, cy, linlog, shape it gives an error. i.e. you need to change the call to polartrans to:<br>
> > > <br>
> > > pim = polartrans(im, nrad, ntheta);<br>
> > > <br>
> > > <br>
> > > "Darren g" wrote in message <k8duk1$kjn$1@newscl01ah.mathworks.com>...<br>
> > > > Hi Phillip,<br>
> > > > <br>
> > > > Thanks for the detailed information. I am not an expert in matlab but currently learning for this image rotation measurement. I have tried the polartrans.m function. But, when calling this function what values I need to supply within the code. I tried nrad=256 and ntheta=360, are the width of my image and a full range of theta. My understanding is that the other parameters cx, cy, linlog, shape should take some default values but when running the code it show error "??? Undefined function or variable 'cx'". Here is the code I tried for polar transform.<br>
> > > > <br>
> > > > a=1;<br>
> > > > image = strcat('',num2str(a,'%04d'),'.png');<br>
> > > > im = imread(image);<br>
> > > > figure(1);<br>
> > > > imagesc(im);<br>
> > > > axis image;<br>
> > > > nrad = 256; ntheta = 360;<br>
> > > > pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape);<br>
> > > > figure(2);<br>
> > > > imagesc(pim);title('Polar transform of image');<br>
> > > > axis image;<br>
> > > > <br>
> > > > Any error in this code?<br>
> > > > <br>
> > > > Thanks in advance.<br>
> > > > Darren<br>
> > > > <br>
> > > > <br>
> > > > "Phillip" wrote in message <k81qc1$app$1@newscl01ah.mathworks.com>...<br>
> > > > > Hi Darren,<br>
> > > > > <br>
> > > > > From the link I gave above, I used the "polartrans.m" file.<br>
> > > > > <br>
> > > > > Once you have the two polar images, do a plain X/Y (translation) crosscorrelation. If the images are just rotated and not stretched, the peak of the crosscorrelation function will be displaced by some amount (I forget in which direction, but should be obvious when you display the images). Each division in the image is worth 2*pi/ntheta angular units (where ntheta is an argument that you give to the polartrans function).<br>
> > > > > <br>
> > > > > If you haven't done a crosscorrelation before, have a look at xcorr2 (I think this requires the signal processing toolbox). Play around with images that just require a translation  once you have that figured out, do the same thing but using your polar images, and multiply by the amount given above to determine the angle.<br>
> > > > > <br>
> > > > > NB: In R2012 onwards the Image Processing toolbox has an "imregister" function that can apparently do all sorts of registrations, including rotations. I find it works well for some kinds of images but not others; you might want to give it a shot.<br>
> > > > > <br>
> > > > > "Darren g" wrote in message <k806kl$s5m$1@newscl01ah.mathworks.com>...<br>
> > > > > > Hi Phillip,<br>
> > > > > > I am also trying to measure the image rotation for very small angle (fractional as well) noisy images. Could you please let me know the function you used from the link you provided. Also, how did you calculate the angle of rotation from the polar transform. I have used polar transform function from the one got from the internet but do not know how to proceed for the angular measurement after polar transforming the two images.<br>
> > > > > > Any help would be much appreciated.<br>
> > > > > > Thanks.<br>
> > > > > > Darren<br>
> > > > > > <br>
> > > > > > "Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > > > > > > > while trying this code i got this error....can you tell me WHY ?????<br>
> > > > > > > > <br>
> > > > > > > > ??? Error using ==> times<br>
> > > > > > > > Matrix dimensions must agree.<br>
> > > > > > > > <br>
> > > > > > > > > for ii = 1:length(thetas)<br>
> > > > > > > > > b = P2(:,ii);<br>
> > > > > > > > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > > > > > > > angle_scores(ii) = max(max(this_correlation));<br>
> > > > > > > > > end<br>
> > > > > > > <br>
> > > > > > > Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> > > > > > > <br>
> > > > > > > However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> > > > > > > <br>
> > > > > > > 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> > > > > > > <br>
> > > > > > > 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> > > > > > > <br>
> > > > > > > I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> > > > > > > I got a Matlab function for creating a polar transform from this page:<br>
> > > > > > > <br>
> > > > > > > <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> > > > > > > <br>
> > > > > > > This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> > > > > > > <br>
> > > > > > > Hope this approach is useful to others.

Tue, 27 Nov 2012 04:28:11 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892467
Phillip
Hi Darren,<br>
<br>
Below is a basic function for finding centre of mass, I can not recall where I stole it from. Try to find the centre of mass in a small region of interest around the peak (instead of using the whole array). Just remember to convert back to whole array coordinates to give the final displacement.<br>
<br>
Phil<br>
<br>
function [a,b] = find_com(x,y,A)<br>
<br>
% Finds centre of mass of matrix A in x, y index notation<br>
<br>
if nargin == 1<br>
A = x;<br>
[Ar Ac] = size(A);<br>
x = 1:Ac;<br>
y = (1:Ar)';<br>
else<br>
y = y(:);<br>
x = (x(:))';<br>
end<br>
<br>
sumA = sum(A(:));<br>
if sumA == 0<br>
a = 0;<br>
b = 0;<br>
else<br>
[row col] = size(A);<br>
% Find centroid across columns:<br>
temp = A.*(ones(row,1)*x);<br>
a = sum(temp(:))/sumA;<br>
% Across rows:<br>
temp = A.*(y*ones(1,col));<br>
b = sum(temp(:))/sumA;<br>
end<br>
<br>
"Darren g" wrote in message <k8v2ok$lam$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> Many thanks. Yes. My code is now working after adopting your suggestion for finding the column and row in which the maximum peak intensity is found. For finding the centre of mass of the image to measure the angle of rotation smaller than one degree I am trying the regionprobs but not yet found a way on how to integrate this within my code. Is this the one you mentioned for finding to centre of mass or any other easy way of doing? Your help for this is much appreciated. <br>
> <br>
> Darren

Wed, 28 Nov 2012 02:34:17 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892572
Darren g
Hi Phillip,<br>
<br>
Thank you for the function details for finding the centre of mass. I have used this function within my code to find the centre of mass of the intensity peak region. However, the angular rotation is not resulting correctly but displayed with four decimal places. Below is the part of the code. The maximum intensity is found at column 361 and row 141 for the first two set of images and a small change for the rest.<br>
<br>
[max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
[max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
%Angle_of_rotation = maxColumn360 % for finding rotation using the intensity peak.<br>
cc1_Matrix = cc_Matrix(130:150,340:380); % only the region surrounding the <br>
% maximum peak is considered.<br>
[a,b] = find_com(cc1_Matrix) % calling function for finding centre of mass<br>
Angle_of_rotation = 340+a360<br>
A1(k,:) = [k, Angle_of_rotation];<br>
disp(A)<br>
<br>
This will give the image no and the angle of rotation of a set of images.<br>
Any error in calling the function or calculation?<br>
<br>
Thanks.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <k91fgr$e3d$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> Below is a basic function for finding centre of mass, I can not recall where I stole it from. Try to find the centre of mass in a small region of interest around the peak (instead of using the whole array). Just remember to convert back to whole array coordinates to give the final displacement.<br>
> <br>
> Phil<br>
> <br>
> function [a,b] = find_com(x,y,A)<br>
> <br>
> % Finds centre of mass of matrix A in x, y index notation<br>
> <br>
> if nargin == 1<br>
> A = x;<br>
> [Ar Ac] = size(A);<br>
> x = 1:Ac;<br>
> y = (1:Ar)';<br>
> else<br>
> y = y(:);<br>
> x = (x(:))';<br>
> end<br>
> <br>
> sumA = sum(A(:));<br>
> if sumA == 0<br>
> a = 0;<br>
> b = 0;<br>
> else<br>
> [row col] = size(A);<br>
> % Find centroid across columns:<br>
> temp = A.*(ones(row,1)*x);<br>
> a = sum(temp(:))/sumA;<br>
> % Across rows:<br>
> temp = A.*(y*ones(1,col));<br>
> b = sum(temp(:))/sumA;<br>
> end<br>
> <br>
> "Darren g" wrote in message <k8v2ok$lam$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > Many thanks. Yes. My code is now working after adopting your suggestion for finding the column and row in which the maximum peak intensity is found. For finding the centre of mass of the image to measure the angle of rotation smaller than one degree I am trying the regionprobs but not yet found a way on how to integrate this within my code. Is this the one you mentioned for finding to centre of mass or any other easy way of doing? Your help for this is much appreciated. <br>
> > <br>
> > Darren

Wed, 28 Nov 2012 22:33:16 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892666
Phillip
Hi Darren,<br>
<br>
Is it a coincidence that the peak of your crosscorrelation appears to be at ~360, or are you getting that confused with the angular expanse of the polar image? What is the array size?<br>
<br>
To avoid confusion you should not "hard code" these numbers. eg for one of your lines I would replace:<br>
cc1_Matrix = cc_Matrix(130:150,340:380); <br>
<br>
With something like:<br>
cc1_Matrix = cc_Matrix(rowCentre  roiDiam/2 : rowCentre + roiDiam/2, colCentre  roiDiam/2 : colCentre + colDiam/2);<br>
<br>
You also have to calculate the angle based on the ntheta input to the polartrans function. For example, if you specified ntheta = 720, each position in the array would be worth 0.5 deg.<br>
<br>
So instead of:<br>
Angle_of_rotation = 340+a360<br>
<br>
Try (I think):<br>
<br>
Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
<br>
Where xSize is the diameter of the whole array.<br>
<br>
Make sure you get an angle of zero for the test case where the images are the same.<br>
<br>
<br>
"Darren g" wrote in message <k93t79$7d3$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> Thank you for the function details for finding the centre of mass. I have used this function within my code to find the centre of mass of the intensity peak region. However, the angular rotation is not resulting correctly but displayed with four decimal places. Below is the part of the code. The maximum intensity is found at column 361 and row 141 for the first two set of images and a small change for the rest.<br>
> <br>
> [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> %Angle_of_rotation = maxColumn360 % for finding rotation using the intensity peak.<br>
> cc1_Matrix = cc_Matrix(130:150,340:380); % only the region surrounding the <br>
> % maximum peak is considered.<br>
> [a,b] = find_com(cc1_Matrix) % calling function for finding centre of mass<br>
> Angle_of_rotation = 340+a360<br>
> A1(k,:) = [k, Angle_of_rotation];<br>
> disp(A)<br>
> <br>
> This will give the image no and the angle of rotation of a set of images.<br>
> Any error in calling the function or calculation?<br>
> <br>
> Thanks.<br>
> Darren

Fri, 30 Nov 2012 02:02:14 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892735
Darren g
Hi Phillip,<br>
<br>
I am completely messed up with the calculation now. Shall we forget about the centre of mass calculation for a moment and find the angle of rotation for one degree precision. <br>
<br>
The test images I used were 283x290 pixels size and one was deliberately rotated with respect to other by 1.4 degrees. <br>
<br>
I used the polartrans function with the following values for these images nrad = 128; <br>
<br>
ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
<br>
and<br>
cc_Matrix = xcorr2(pim1, pim2);<br>
<br>
Now the size(cc_Matrix) gave<br>
ans= <br>
255 719<br>
When I use the following for calculating the maximum intensity and its corresponding column and row it gave <br>
<br>
maxColumn=361 and <br>
maxRow=128<br>
<br>
Since there is no translation and the second image is only rotated with respect to the first (by 1.4 degrees in this case), for the angular rotation calculation we only need the column value in which the maximum intensity is found which is 361 (Is it correct?). <br>
<br>
[max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
[max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
<br>
So the Angle of rotation = maxColumncentre of the cc_matrix column<br>
=361360<br>
Which resulted in the 1 degree.<br>
Is anything wrong with this calculation?<br>
<br>
Now move on to the centre of mass calculation.<br>
<br>
Would you mean maxColumn and maxRow by rowCentre and colCentre in the following centre of mass (COM) calculation? Is roiDiam is the width of the square area considered for this COM calculation?<br>
<br>
cc1_Matrix = cc_Matrix(rowCentre  roiDiam/2 : rowCentre + roiDiam/2, colCentre  roiDiam/2 : colCentre + roiDiam/2);<br>
<br>
Is xSize is the diameter of the cc_Matrix in the following?<br>
<br>
Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
<br>
Sorry for these lengthy explanation and clarification but I hope this will give an idea to find out the error in my thinking.<br>
<br>
Thanks.<br>
Darren<br>
<br>
"Phillip" wrote in message <k963fc$fb5$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> Is it a coincidence that the peak of your crosscorrelation appears to be at ~360, or are you getting that confused with the angular expanse of the polar image? What is the array size?<br>
> <br>
> To avoid confusion you should not "hard code" these numbers. eg for one of your lines I would replace:<br>
> cc1_Matrix = cc_Matrix(130:150,340:380); <br>
> <br>
> With something like:<br>
> cc1_Matrix = cc_Matrix(rowCentre  roiDiam/2 : rowCentre + roiDiam/2, colCentre  roiDiam/2 : colCentre + colDiam/2);<br>
> <br>
> You also have to calculate the angle based on the ntheta input to the polartrans function. For example, if you specified ntheta = 720, each position in the array would be worth 0.5 deg.<br>
> <br>
> So instead of:<br>
> Angle_of_rotation = 340+a360<br>
> <br>
> Try (I think):<br>
> <br>
> Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
> <br>
> Where xSize is the diameter of the whole array.<br>
> <br>
> Make sure you get an angle of zero for the test case where the images are the same.<br>
> <br>
> <br>
> "Darren g" wrote in message <k93t79$7d3$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > Thank you for the function details for finding the centre of mass. I have used this function within my code to find the centre of mass of the intensity peak region. However, the angular rotation is not resulting correctly but displayed with four decimal places. Below is the part of the code. The maximum intensity is found at column 361 and row 141 for the first two set of images and a small change for the rest.<br>
> > <br>
> > [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> > [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> > %Angle_of_rotation = maxColumn360 % for finding rotation using the intensity peak.<br>
> > cc1_Matrix = cc_Matrix(130:150,340:380); % only the region surrounding the <br>
> > % maximum peak is considered.<br>
> > [a,b] = find_com(cc1_Matrix) % calling function for finding centre of mass<br>
> > Angle_of_rotation = 340+a360<br>
> > A1(k,:) = [k, Angle_of_rotation];<br>
> > disp(A)<br>
> > <br>
> > This will give the image no and the angle of rotation of a set of images.<br>
> > Any error in calling the function or calculation?<br>
> > <br>
> > Thanks.<br>
> > Darren

Sun, 02 Dec 2012 23:17:08 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#892905
Phillip
Hi Darren,<br>
<br>
In regards to the first part, the mid point for a 255 x 719 matrix is 127, 359. So that would imply some sort of error. Try subtracting the mean of both images just before the call to xcorr2, I think this is necessary for the correlation to work. i.e.<br>
<br>
pim1 = pim1  mean(mean(pim1));<br>
pim2 = pim2  mean(mean(pim2));<br>
<br>
You might want to test your correlation routine out on a simple translation first. eg the code below will give you a 20 pixel vertical translation <br>
<br>
xShift = 0;<br>
yShift = 20;<br>
translatingElement = translate(strel(1), [yShift xShift]);<br>
image2 = imdilate(image1,translatingElement);<br>
<br>
image1 = image1(1+yShift:endyShift,1+xShift:endxShift); % get rid of Infs from the imdilate function<br>
image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
<br>
For your other questions:<br>
> Would you mean maxColumn and maxRow by rowCentre and colCentre in the following centre of mass (COM) calculation? Is roiDiam is the width of the square area considered for this COM calculation?<br>
<br>
Yes.<br>
<br>
> Is xSize is the diameter of the cc_Matrix in the following?<br>
> <br>
> Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
<br>
Yes.<br>
<br>
Hope this helps.<br>
<br>
Phillip<br>
<br>
"Darren g" wrote in message <k99436$9u7$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> I am completely messed up with the calculation now. Shall we forget about the centre of mass calculation for a moment and find the angle of rotation for one degree precision. <br>
> <br>
> The test images I used were 283x290 pixels size and one was deliberately rotated with respect to other by 1.4 degrees. <br>
> <br>
> I used the polartrans function with the following values for these images nrad = 128; <br>
> <br>
> ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
> pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> <br>
> and<br>
> cc_Matrix = xcorr2(pim1, pim2);<br>
> <br>
> Now the size(cc_Matrix) gave<br>
> ans= <br>
> 255 719<br>
> When I use the following for calculating the maximum intensity and its corresponding column and row it gave <br>
> <br>
> maxColumn=361 and <br>
> maxRow=128<br>
> <br>
> Since there is no translation and the second image is only rotated with respect to the first (by 1.4 degrees in this case), for the angular rotation calculation we only need the column value in which the maximum intensity is found which is 361 (Is it correct?). <br>
> <br>
> [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> <br>
> So the Angle of rotation = maxColumncentre of the cc_matrix column<br>
> =361360<br>
> Which resulted in the 1 degree.<br>
> Is anything wrong with this calculation?<br>
> <br>
> Now move on to the centre of mass calculation.<br>
> <br>
> Would you mean maxColumn and maxRow by rowCentre and colCentre in the following centre of mass (COM) calculation? Is roiDiam is the width of the square area considered for this COM calculation?<br>
> <br>
> cc1_Matrix = cc_Matrix(rowCentre  roiDiam/2 : rowCentre + roiDiam/2, colCentre  roiDiam/2 : colCentre + roiDiam/2);<br>
> <br>
> Is xSize is the diameter of the cc_Matrix in the following?<br>
> <br>
> Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
> <br>
> Sorry for these lengthy explanation and clarification but I hope this will give an idea to find out the error in my thinking.<br>
> <br>
> Thanks.<br>
> Darren<br>
>

Tue, 04 Dec 2012 00:02:29 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893004
Darren g
Hi Phillip,<br>
<br>
I think the problem is in the Angle of rotation calculation equation but I could not figure out how to change it.<br>
Here is the code I used to check with the code you provided to introducing the image shift.<br>
<br>
clear all;<br>
image1 = imread('0001.png');<br>
<br>
xShift = 0;<br>
yShift = 20;<br>
translatingElement = translate(strel(1), [yShift xShift]);<br>
image2 = imdilate(image1,translatingElement);<br>
<br>
image1 = image1(1+yShift:endyShift,1+xShift:endxShift); <br>
% get rid of Infs from the imdilate function<br>
image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
<br>
nrad = 128; ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
% cx & cy for a 283x290 pixels image<br>
<br>
pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
<br>
pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
<br>
pim1 = pim1  mean(mean(pim1));<br>
pim2 = pim2  mean(mean(pim2));<br>
<br>
cc_Matrix = xcorr2(pim1, pim2);<br>
figure (1);<br>
imagesc(cc_Matrix);<br>
axis image;<br>
[max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
[max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
<br>
roiDiam = 20;<br>
cc1_Matrix = cc_Matrix(maxRowroiDiam/2:maxRow+roiDiam/2, maxColumnroiDiam/2:maxColumn+roiDiam/2); <br>
figure (2);<br>
imagesc(cc1_Matrix);<br>
axis image;<br>
[a,b] = find_com(cc1_Matrix) % calling function<br>
<br>
Angle_of_rotation = (a + maxColumn  length(cc1_Matrix)/2) * 360/ntheta<br>
<br>
Could you pls have a look of this with any of your random image?<br>
<br>
Thanks.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <k9gnhk$d5h$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> In regards to the first part, the mid point for a 255 x 719 matrix is 127, 359. So that would imply some sort of error. Try subtracting the mean of both images just before the call to xcorr2, I think this is necessary for the correlation to work. i.e.<br>
> <br>
> pim1 = pim1  mean(mean(pim1));<br>
> pim2 = pim2  mean(mean(pim2));<br>
> <br>
> You might want to test your correlation routine out on a simple translation first. eg the code below will give you a 20 pixel vertical translation <br>
> <br>
> xShift = 0;<br>
> yShift = 20;<br>
> translatingElement = translate(strel(1), [yShift xShift]);<br>
> image2 = imdilate(image1,translatingElement);<br>
> <br>
> image1 = image1(1+yShift:endyShift,1+xShift:endxShift); % get rid of Infs from the imdilate function<br>
> image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
> <br>
> For your other questions:<br>
> > Would you mean maxColumn and maxRow by rowCentre and colCentre in the following centre of mass (COM) calculation? Is roiDiam is the width of the square area considered for this COM calculation?<br>
> <br>
> Yes.<br>
> <br>
> > Is xSize is the diameter of the cc_Matrix in the following?<br>
> > <br>
> > Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
> <br>
> Yes.<br>
> <br>
> Hope this helps.<br>
> <br>
> Phillip<br>
> <br>
> "Darren g" wrote in message <k99436$9u7$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > I am completely messed up with the calculation now. Shall we forget about the centre of mass calculation for a moment and find the angle of rotation for one degree precision. <br>
> > <br>
> > The test images I used were 283x290 pixels size and one was deliberately rotated with respect to other by 1.4 degrees. <br>
> > <br>
> > I used the polartrans function with the following values for these images nrad = 128; <br>
> > <br>
> > ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
> > pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> > pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> > <br>
> > and<br>
> > cc_Matrix = xcorr2(pim1, pim2);<br>
> > <br>
> > Now the size(cc_Matrix) gave<br>
> > ans= <br>
> > 255 719<br>
> > When I use the following for calculating the maximum intensity and its corresponding column and row it gave <br>
> > <br>
> > maxColumn=361 and <br>
> > maxRow=128<br>
> > <br>
> > Since there is no translation and the second image is only rotated with respect to the first (by 1.4 degrees in this case), for the angular rotation calculation we only need the column value in which the maximum intensity is found which is 361 (Is it correct?). <br>
> > <br>
> > [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> > [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> > <br>
> > So the Angle of rotation = maxColumncentre of the cc_matrix column<br>
> > =361360<br>
> > Which resulted in the 1 degree.<br>
> > Is anything wrong with this calculation?<br>
> > <br>
> > Now move on to the centre of mass calculation.<br>
> > <br>
> > Would you mean maxColumn and maxRow by rowCentre and colCentre in the following centre of mass (COM) calculation? Is roiDiam is the width of the square area considered for this COM calculation?<br>
> > <br>
> > cc1_Matrix = cc_Matrix(rowCentre  roiDiam/2 : rowCentre + roiDiam/2, colCentre  roiDiam/2 : colCentre + roiDiam/2);<br>
> > <br>
> > Is xSize is the diameter of the cc_Matrix in the following?<br>
> > <br>
> > Angle_of_rotation = (a + colCentre  xSize/2) * 360/ntheta<br>
> > <br>
> > Sorry for these lengthy explanation and clarification but I hope this will give an idea to find out the error in my thinking.<br>
> > <br>
> > Thanks.<br>
> > Darren<br>
> >

Tue, 04 Dec 2012 06:08:08 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893023
Phillip
Hi Darren,<br>
<br>
That code to do the image shift gives a pure translation. But then you are trying to take the polar transform, and determine an angle of rotation (!). So I would remove that polar image stuff and just try to extract the translation amount (i.e. you should caluclate a displacement of 20 pixels in the vertical direction).<br>
<br>
Once you have that down pat, you can switch to rotating the image, doing the polar transform, and doing the xcorr of that. To rotate the image you can do something like<br>
<br>
rotatedImage = imrotate(image1,angleInDegrees,'crop','bilinear');<br>
<br>
Then finally, you can test your code by both translating and shifting the image. To solve this I usually do an initial translation correction (Cartesian images), followed by a rotation correction (polar images), then a final translation correction (Cartesian images) to mop up any residual errors.<br>
<br>
Cheers,<br>
<br>
Phillip<br>
<br>
"Darren g" wrote in message <k9jeil$gc6$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> I think the problem is in the Angle of rotation calculation equation but I could not figure out how to change it.<br>
> Here is the code I used to check with the code you provided to introducing the image shift.<br>
> <br>
> clear all;<br>
> image1 = imread('0001.png');<br>
> <br>
> xShift = 0;<br>
> yShift = 20;<br>
> translatingElement = translate(strel(1), [yShift xShift]);<br>
> image2 = imdilate(image1,translatingElement);<br>
> <br>
> image1 = image1(1+yShift:endyShift,1+xShift:endxShift); <br>
> % get rid of Infs from the imdilate function<br>
> image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
> <br>
> nrad = 128; ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
> % cx & cy for a 283x290 pixels image<br>
> <br>
> pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> <br>
> pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> <br>
> pim1 = pim1  mean(mean(pim1));<br>
> pim2 = pim2  mean(mean(pim2));<br>
> <br>
> cc_Matrix = xcorr2(pim1, pim2);<br>
> figure (1);<br>
> imagesc(cc_Matrix);<br>
> axis image;<br>
> [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> <br>
> roiDiam = 20;<br>
> cc1_Matrix = cc_Matrix(maxRowroiDiam/2:maxRow+roiDiam/2, maxColumnroiDiam/2:maxColumn+roiDiam/2); <br>
> figure (2);<br>
> imagesc(cc1_Matrix);<br>
> axis image;<br>
> [a,b] = find_com(cc1_Matrix) % calling function<br>
> <br>
> Angle_of_rotation = (a + maxColumn  length(cc1_Matrix)/2) * 360/ntheta<br>
> <br>
> Could you pls have a look of this with any of your random image?<br>
> <br>
> Thanks.<br>
> Darren

Tue, 11 Dec 2012 11:14:08 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893511
Darren g
Hi Phillip,<br>
<br>
Thanks. I have tried the following code for measuring the pure shift but it show the error <br>
<br>
Warning: CONV2 on values of class UINT8 is obsolete.<br>
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead. <br>
> In uint8.conv2 at 11<br>
In xcorr2 at 17<br>
In translation at 18 <br>
<br>
The code is here.<br>
<br>
clear all;<br>
image1 = imread('0001.jpg');<br>
<br>
xShift = 0;<br>
yShift = 20;<br>
translatingElement = translate(strel(1), [yShift xShift]);<br>
image2 = imdilate(image1,translatingElement);<br>
image1 = image1(1+yShift:endyShift,1+xShift:endxShift);<br>
% get rid of Infs from the imdilate function<br>
image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
figure (1);<br>
imagesc(image1);<br>
axis image;<br>
figure (2);<br>
imagesc(image2);<br>
axis image;<br>
<br>
d = xcorr2(image1,image2);<br>
figure (3);<br>
imagesc(d);<br>
axis image;<br>
[maxd, maxd_pos_Col] = max(max(d))<br>
[maxd, maxd_pos_Row] = max(d(:, maxd_pos_Col))<br>
<br>
Shift = RowCentre  maxd_pos_Row<br>
<br>
I could not figure out the error?<br>
<br>
Thanks.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <k9k408$p5c$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> That code to do the image shift gives a pure translation. But then you are trying to take the polar transform, and determine an angle of rotation (!). So I would remove that polar image stuff and just try to extract the translation amount (i.e. you should caluclate a displacement of 20 pixels in the vertical direction).<br>
> <br>
> Once you have that down pat, you can switch to rotating the image, doing the polar transform, and doing the xcorr of that. To rotate the image you can do something like<br>
> <br>
> rotatedImage = imrotate(image1,angleInDegrees,'crop','bilinear');<br>
> <br>
> Then finally, you can test your code by both translating and shifting the image. To solve this I usually do an initial translation correction (Cartesian images), followed by a rotation correction (polar images), then a final translation correction (Cartesian images) to mop up any residual errors.<br>
> <br>
> Cheers,<br>
> <br>
> Phillip<br>
> <br>
> "Darren g" wrote in message <k9jeil$gc6$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > I think the problem is in the Angle of rotation calculation equation but I could not figure out how to change it.<br>
> > Here is the code I used to check with the code you provided to introducing the image shift.<br>
> > <br>
> > clear all;<br>
> > image1 = imread('0001.png');<br>
> > <br>
> > xShift = 0;<br>
> > yShift = 20;<br>
> > translatingElement = translate(strel(1), [yShift xShift]);<br>
> > image2 = imdilate(image1,translatingElement);<br>
> > <br>
> > image1 = image1(1+yShift:endyShift,1+xShift:endxShift); <br>
> > % get rid of Infs from the imdilate function<br>
> > image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
> > <br>
> > nrad = 128; ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5; <br>
> > % cx & cy for a 283x290 pixels image<br>
> > <br>
> > pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> > <br>
> > pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');<br>
> > <br>
> > pim1 = pim1  mean(mean(pim1));<br>
> > pim2 = pim2  mean(mean(pim2));<br>
> > <br>
> > cc_Matrix = xcorr2(pim1, pim2);<br>
> > figure (1);<br>
> > imagesc(cc_Matrix);<br>
> > axis image;<br>
> > [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))<br>
> > [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))<br>
> > <br>
> > roiDiam = 20;<br>
> > cc1_Matrix = cc_Matrix(maxRowroiDiam/2:maxRow+roiDiam/2, maxColumnroiDiam/2:maxColumn+roiDiam/2); <br>
> > figure (2);<br>
> > imagesc(cc1_Matrix);<br>
> > axis image;<br>
> > [a,b] = find_com(cc1_Matrix) % calling function<br>
> > <br>
> > Angle_of_rotation = (a + maxColumn  length(cc1_Matrix)/2) * 360/ntheta<br>
> > <br>
> > Could you pls have a look of this with any of your random image?<br>
> > <br>
> > Thanks.<br>
> > Darren

Tue, 11 Dec 2012 22:54:09 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893543
Phillip
Hi Darren,<br>
<br>
The warning appears because you can't do much useful maths on an integer array. Just follow the suggestion shown in the warning. This will convert the image from integer to double/single precision "float" (i.e. a number that can have decimal points). Single uses half the memory but you get half the precision in terms of decimal points etc... generally use single if you are worried about memory issues, otherwise, you may as well use double. The default for new Matlab variables is double.<br>
<br>
Cheers,<br>
<br>
Phillip<br>
<br>
"Darren g" wrote in message <ka74i0$32b$1@newscl01ah.mathworks.com>...<br>
> Hi Phillip,<br>
> <br>
> Thanks. I have tried the following code for measuring the pure shift but it show the error <br>
> <br>
> Warning: CONV2 on values of class UINT8 is obsolete.<br>
> Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead. <br>
> > In uint8.conv2 at 11<br>
> In xcorr2 at 17<br>
> In translation at 18 <br>
> <br>
> The code is here.<br>
> <br>
> clear all;<br>
> image1 = imread('0001.jpg');<br>
> <br>
> xShift = 0;<br>
> yShift = 20;<br>
> translatingElement = translate(strel(1), [yShift xShift]);<br>
> image2 = imdilate(image1,translatingElement);<br>
> image1 = image1(1+yShift:endyShift,1+xShift:endxShift);<br>
> % get rid of Infs from the imdilate function<br>
> image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
> figure (1);<br>
> imagesc(image1);<br>
> axis image;<br>
> figure (2);<br>
> imagesc(image2);<br>
> axis image;<br>
> <br>
> d = xcorr2(image1,image2);<br>
> figure (3);<br>
> imagesc(d);<br>
> axis image;<br>
> [maxd, maxd_pos_Col] = max(max(d))<br>
> [maxd, maxd_pos_Row] = max(d(:, maxd_pos_Col))<br>
> <br>
> Shift = RowCentre  maxd_pos_Row<br>
> <br>
> I could not figure out the error?<br>
> <br>
> Thanks.<br>
> Darren

Wed, 12 Dec 2012 18:29:08 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893598
Darren g
Hi Phillip,<br>
<br>
Would you mean to change the conv2 function within the corresponding folder.<br>
I tried replacing it with double but now show another error.<br>
<br>
Error: File: conv2.m Line: 1 Column: 26<br>
Unbalanced or unexpected parenthesis or bracket.<br>
<br>
Error in xcorr2 (line 17)<br>
c = conv2(a, rot90(conj(b),2));<br>
<br>
Error in translation (line 18)<br>
d = xcorr2(image1,image2);<br>
<br>
Thanks.<br>
Darren<br>
<br>
<br>
"Phillip" wrote in message <ka8dih$8d6$1@newscl01ah.mathworks.com>...<br>
> Hi Darren,<br>
> <br>
> The warning appears because you can't do much useful maths on an integer array. Just follow the suggestion shown in the warning. This will convert the image from integer to double/single precision "float" (i.e. a number that can have decimal points). Single uses half the memory but you get half the precision in terms of decimal points etc... generally use single if you are worried about memory issues, otherwise, you may as well use double. The default for new Matlab variables is double.<br>
> <br>
> Cheers,<br>
> <br>
> Phillip<br>
> <br>
> "Darren g" wrote in message <ka74i0$32b$1@newscl01ah.mathworks.com>...<br>
> > Hi Phillip,<br>
> > <br>
> > Thanks. I have tried the following code for measuring the pure shift but it show the error <br>
> > <br>
> > Warning: CONV2 on values of class UINT8 is obsolete.<br>
> > Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead. <br>
> > > In uint8.conv2 at 11<br>
> > In xcorr2 at 17<br>
> > In translation at 18 <br>
> > <br>
> > The code is here.<br>
> > <br>
> > clear all;<br>
> > image1 = imread('0001.jpg');<br>
> > <br>
> > xShift = 0;<br>
> > yShift = 20;<br>
> > translatingElement = translate(strel(1), [yShift xShift]);<br>
> > image2 = imdilate(image1,translatingElement);<br>
> > image1 = image1(1+yShift:endyShift,1+xShift:endxShift);<br>
> > % get rid of Infs from the imdilate function<br>
> > image2 = image2(1+yShift:endyShift,1+xShift:endxShift);<br>
> > figure (1);<br>
> > imagesc(image1);<br>
> > axis image;<br>
> > figure (2);<br>
> > imagesc(image2);<br>
> > axis image;<br>
> > <br>
> > d = xcorr2(image1,image2);<br>
> > figure (3);<br>
> > imagesc(d);<br>
> > axis image;<br>
> > [maxd, maxd_pos_Col] = max(max(d))<br>
> > [maxd, maxd_pos_Row] = max(d(:, maxd_pos_Col))<br>
> > <br>
> > Shift = RowCentre  maxd_pos_Row<br>
> > <br>
> > I could not figure out the error?<br>
> > <br>
> > Thanks.<br>
> > Darren

Wed, 12 Dec 2012 18:43:57 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#893600
Steven_Lord
<br>
<br>
"Darren g" <darreng212@yahoo.com> wrote in message <br>
news:kaaidk$6jc$1@newscl01ah.mathworks.com...<br>
> Hi Phillip,<br>
><br>
> Would you mean to change the conv2 function within the corresponding <br>
> folder.<br>
> I tried replacing it with double but now show another error.<br>
><br>
> Error: File: conv2.m Line: 1 Column: 26<br>
> Unbalanced or unexpected parenthesis or bracket.<br>
><br>
> Error in xcorr2 (line 17)<br>
> c = conv2(a, rot90(conj(b),2));<br>
><br>
> Error in translation (line 18)<br>
> d = xcorr2(image1,image2);<br>
<br>
Revert your changes to CONV2 then change your translation function or script <br>
to pass double(image1) and double(image2) into XCORR2 rather than image1 and <br>
image2.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
To contact Technical Support use the Contact Us link on <br>
<a href="http://www.mathworks.com">http://www.mathworks.com</a>

Thu, 20 Dec 2012 04:46:09 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#894017
Kev
This solution is super useful for my application. I am basically working on an feature tracking/pattern recognition application and my method has to be rotation and intensity invariant. So one question is that will I get a higher xcorr peak if the 2 images are matching compared to none matching ones?<br>
<br>
Cheers,<br>
K<br>
"Phillip" wrote in message <ierba4$kko$1@fred.mathworks.com>...<br>
> > while trying this code i got this error....can you tell me WHY ?????<br>
> > <br>
> > ??? Error using ==> times<br>
> > Matrix dimensions must agree.<br>
> > <br>
> > > for ii = 1:length(thetas)<br>
> > > b = P2(:,ii);<br>
> > > this_correlation = abs(ifft(P1.*conj(b)));<br>
> > > angle_scores(ii) = max(max(this_correlation));<br>
> > > end<br>
> <br>
> Make sure that P1 is a column vector and P2 has the same number of rows as P1.<br>
> <br>
> However, I've changed the way I solve this problem now. Two points to note for anybody stumbling on this:<br>
> <br>
> 1) What I said about only needing one radon projection for the reference might be true in theory, but I found in practice with noisy data that this was not so good. I've actually abandoned the radon approach.<br>
> <br>
> 2) I now solve my rotation problem in an entirely different way. I'm not sure how generally applicable this solution is, but it worked well for my application (very large images, only small angles of rotation possible, very precise estimate of rotation necessary).<br>
> <br>
> I find the polar transforms of the reference and acquired images, and then do a typical registration between these using crosscorrelation. The shift required in the theta dimension tells you the rotation required (the other dimension has radius info which I don't use). <br>
> I got a Matlab function for creating a polar transform from this page:<br>
> <br>
> <a href="http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/">http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/</a><br>
> <br>
> This function lets you specify the sampling in both the theta and radial dimensions. I upsample quite a bit in the theta dimension (better precision on the angle estimate) and downsample in the radial dimension (to keep memory costs down  my images are quite large).<br>
> <br>
> Hope this approach is useful to others.

Thu, 20 Dec 2012 22:33:10 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#894078
Phillip
It's true that for a given pair of images the cross correlation peak will be higher when they are registered correctly. But it is possible for one pair to have a higher peak than another pair even if the latter is better aligned  it all depends on the images. In other words, the value at the peak is not directly comparable across image pairs (unless the image pairs all have quite similar spatial content).<br>
<br>
"Kev " <piakster@gmail.com> wrote in message <kau56h$9p7$1@newscl01ah.mathworks.com>...<br>
> This solution is super useful for my application. I am basically working on an feature tracking/pattern recognition application and my method has to be rotation and intensity invariant. So one question is that will I get a higher xcorr peak if the 2 images are matching compared to none matching ones?<br>
> <br>
> Cheers,<br>
> K

Fri, 21 Dec 2012 03:15:10 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#894082
Kev
Hi Phillip,<br>
<br>
Thanks for replying. I do not get the part on correct registration. Say if I have an image of the letter 'A' rotated. I try to do a xcorr of the polar transform of this image with the image of the letter 'A' upright. The peak of the xcorr will be higher than xcorr of a letter 'B' with 'A' right?<br>
<br>
K<br>
"Phillip" wrote in message <kb03n6$n63$1@newscl01ah.mathworks.com>...<br>
> It's true that for a given pair of images the cross correlation peak will be higher when they are registered correctly. But it is possible for one pair to have a higher peak than another pair even if the latter is better aligned  it all depends on the images. In other words, the value at the peak is not directly comparable across image pairs (unless the image pairs all have quite similar spatial content).<br>
> <br>
> "Kev " <piakster@gmail.com> wrote in message <kau56h$9p7$1@newscl01ah.mathworks.com>...<br>
> > This solution is super useful for my application. I am basically working on an feature tracking/pattern recognition application and my method has to be rotation and intensity invariant. So one question is that will I get a higher xcorr peak if the 2 images are matching compared to none matching ones?<br>
> > <br>
> > Cheers,<br>
> > K

Fri, 21 Dec 2012 03:17:19 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#894083
Kev
Hi Phillip,<br>
<br>
Thanks for replying. I do not get the part on correct registration. Say if I have an image of the letter 'A' rotated. I try to do a xcorr of the polar transform of this image with the image of the letter 'A' upright. The peak of the xcorr will be higher than xcorr of a letter 'B' with 'A' right?<br>
<br>
K<br>
"Phillip" wrote in message <kb03n6$n63$1@newscl01ah.mathworks.com>...<br>
> It's true that for a given pair of images the cross correlation peak will be higher when they are registered correctly. But it is possible for one pair to have a higher peak than another pair even if the latter is better aligned  it all depends on the images. In other words, the value at the peak is not directly comparable across image pairs (unless the image pairs all have quite similar spatial content).<br>
> <br>
> "Kev " <piakster@gmail.com> wrote in message <kau56h$9p7$1@newscl01ah.mathworks.com>...<br>
> > This solution is super useful for my application. I am basically working on an feature tracking/pattern recognition application and my method has to be rotation and intensity invariant. So one question is that will I get a higher xcorr peak if the 2 images are matching compared to none matching ones?<br>
> > <br>
> > Cheers,<br>
> > K

Wed, 06 Feb 2013 12:25:08 +0000
Re: Image rotation detection probelm
http://www.mathworks.com/matlabcentral/newsreader/view_thread/254141#897281
Darren g
Dear Steve,<br>
<br>
Thanks for your suggestion for changing to double. It took some time for me to work on the code again for some other reasons. Come back if any help needed.<br>
<br>
Thanks.<br>
Darren<br>
<br>
"Steven_Lord" <slord@mathworks.com> wrote in message <kaaj9e$9s0$1@newscl01ah.mathworks.com>...<br>
> <br>
> <br>
> "Darren g" <darreng212@yahoo.com> wrote in message <br>
> news:kaaidk$6jc$1@newscl01ah.mathworks.com...<br>
> > Hi Phillip,<br>
> ><br>
> > Would you mean to change the conv2 function within the corresponding <br>
> > folder.<br>
> > I tried replacing it with double but now show another error.<br>
> ><br>
> > Error: File: conv2.m Line: 1 Column: 26<br>
> > Unbalanced or unexpected parenthesis or bracket.<br>
> ><br>
> > Error in xcorr2 (line 17)<br>
> > c = conv2(a, rot90(conj(b),2));<br>
> ><br>
> > Error in translation (line 18)<br>
> > d = xcorr2(image1,image2);<br>
> <br>
> Revert your changes to CONV2 then change your translation function or script <br>
> to pass double(image1) and double(image2) into XCORR2 rather than image1 and <br>
> image2.<br>
> <br>
>  <br>
> Steve Lord<br>
> slord@mathworks.com<br>
> To contact Technical Support use the Contact Us link on <br>
> <a href="http://www.mathworks.com">http://www.mathworks.com</a>