Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Image rotation detection probelm
Replies: 32   Last Post: Aug 8, 2013 10:46 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Darren g

Posts: 10
Registered: 11/14/12
Re: Image rotation detection probelm
Posted: Nov 29, 2012 9:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi Phillip,

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.

The test images I used were 283x290 pixels size and one was deliberately rotated with respect to other by 1.4 degrees.

I used the polartrans function with the following values for these images nrad = 128;

ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5;
pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');
pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');

and
cc_Matrix = xcorr2(pim1, pim2);

Now the size(cc_Matrix) gave
ans=
255 719
When I use the following for calculating the maximum intensity and its corresponding column and row it gave

maxColumn=361 and
maxRow=128

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

[max_cc_Matrix, maxColumn] = max(max(cc_Matrix))
[max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))

So the Angle of rotation = maxColumn-centre of the cc_matrix column
=361-360
Which resulted in the 1 degree.
Is anything wrong with this calculation?

Now move on to the centre of mass calculation.

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?

cc1_Matrix = cc_Matrix(rowCentre - roiDiam/2 : rowCentre + roiDiam/2, colCentre - roiDiam/2 : colCentre + roiDiam/2);

Is xSize is the diameter of the cc_Matrix in the following?

Angle_of_rotation = (a + colCentre - xSize/2) * 360/ntheta

Sorry for these lengthy explanation and clarification but I hope this will give an idea to find out the error in my thinking.

Thanks.
Darren

"Phillip" wrote in message <k963fc$fb5$1@newscl01ah.mathworks.com>...
> Hi Darren,
>
> Is it a coincidence that the peak of your cross-correlation appears to be at ~360, or are you getting that confused with the angular expanse of the polar image? What is the array size?
>
> To avoid confusion you should not "hard code" these numbers. eg for one of your lines I would replace:
> cc1_Matrix = cc_Matrix(130:150,340:380);
>
> With something like:
> cc1_Matrix = cc_Matrix(rowCentre - roiDiam/2 : rowCentre + roiDiam/2, colCentre - roiDiam/2 : colCentre + colDiam/2);
>
> 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.
>
> So instead of:
> Angle_of_rotation = 340+a-360
>
> Try (I think):
>
> Angle_of_rotation = (a + colCentre - xSize/2) * 360/ntheta
>
> Where xSize is the diameter of the whole array.
>
> Make sure you get an angle of zero for the test case where the images are the same.
>
>
> "Darren g" wrote in message <k93t79$7d3$1@newscl01ah.mathworks.com>...

> > Hi Phillip,
> >
> > 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.
> >
> > [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))
> > [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))
> > %Angle_of_rotation = maxColumn-360 % for finding rotation using the intensity peak.
> > cc1_Matrix = cc_Matrix(130:150,340:380); % only the region surrounding the
> > % maximum peak is considered.
> > [a,b] = find_com(cc1_Matrix) % calling function for finding centre of mass
> > Angle_of_rotation = 340+a-360
> > A1(k,:) = [k, Angle_of_rotation];
> > disp(A)
> >
> > This will give the image no and the angle of rotation of a set of images.
> > Any error in calling the function or calculation?
> >
> > Thanks.
> > Darren



Date Subject Author
6/19/09
Read Image rotation detection probelm
Pradyumna A
6/19/09
Read Re: Image rotation detection probelm
Matt
9/16/09
Read Re: Image rotation detection probelm
Hamid Reza Mohseni Nejad
8/2/10
Read Re: Image rotation detection probelm
Phillip
12/21/10
Read Re: Image rotation detection probelm
chee ali
12/21/10
Read Re: Image rotation detection probelm
Phillip
12/21/10
Read Re: Image rotation detection probelm
Matt J
12/21/10
Read Re: Image rotation detection probelm
Phillip
11/14/12
Read Re: Image rotation detection probelm
Darren g
11/14/12
Read Re: Image rotation detection probelm
Phillip
11/19/12
Read Re: Image rotation detection probelm
Darren g
11/19/12
Read Re: Image rotation detection probelm
Phillip
11/20/12
Read Re: Image rotation detection probelm
Darren g
11/20/12
Read Re: Image rotation detection probelm
Phillip
11/26/12
Read Re: Image rotation detection probelm
Darren g
11/26/12
Read Re: Image rotation detection probelm
Phillip
11/27/12
Read Re: Image rotation detection probelm
Darren g
11/28/12
Read Re: Image rotation detection probelm
Phillip
11/29/12
Read Re: Image rotation detection probelm
Darren g
12/2/12
Read Re: Image rotation detection probelm
Phillip
12/3/12
Read Re: Image rotation detection probelm
Darren g
12/4/12
Read Re: Image rotation detection probelm
Phillip
12/11/12
Read Re: Image rotation detection probelm
Darren g
12/11/12
Read Re: Image rotation detection probelm
Phillip
12/12/12
Read Re: Image rotation detection probelm
Darren g
12/12/12
Read Re: Image rotation detection probelm
Steven Lord
2/6/13
Read Re: Image rotation detection probelm
Darren g
12/20/12
Read Re: Image rotation detection probelm
Phillip
12/20/12
Read Re: Image rotation detection probelm
Kev
12/20/12
Read Re: Image rotation detection probelm
Kev
7/7/13
Read Re: Image rotation detection probelm
xmlfor
8/8/13
Read Re: Image rotation detection probelm
jacaboo

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.