Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Darren g Posts: 10 Registered: 11/14/12
Re: Image rotation detection probelm
Posted: Dec 11, 2012 6:14 AM
 Plain Text Reply

Hi Phillip,

Thanks. I have tried the following code for measuring the pure shift but it show the error

Warning: CONV2 on values of class UINT8 is obsolete.
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead.
> In uint8.conv2 at 11
In xcorr2 at 17
In translation at 18

The code is here.

clear all;
image1 = imread('0001.jpg');

xShift = 0;
yShift = 20;
translatingElement = translate(strel(1), [yShift xShift]);
image2 = imdilate(image1,translatingElement);
image1 = image1(1+yShift:end-yShift,1+xShift:end-xShift);
% get rid of Infs from the imdilate function
image2 = image2(1+yShift:end-yShift,1+xShift:end-xShift);
figure (1);
imagesc(image1);
axis image;
figure (2);
imagesc(image2);
axis image;

d = xcorr2(image1,image2);
figure (3);
imagesc(d);
axis image;
[maxd, maxd_pos_Col] = max(max(d))
[maxd, maxd_pos_Row] = max(d(:, maxd_pos_Col))

Shift = RowCentre - maxd_pos_Row

I could not figure out the error?

Thanks.
Darren

"Phillip" wrote in message <k9k408\$p5c\$1@newscl01ah.mathworks.com>...
> Hi Darren,
>
> 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).
>
> 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
>
> rotatedImage = imrotate(image1,angleInDegrees,'crop','bilinear');
>
> 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.
>
> Cheers,
>
> Phillip
>
> "Darren g" wrote in message <k9jeil\$gc6\$1@newscl01ah.mathworks.com>...

> > Hi Phillip,
> >
> > I think the problem is in the Angle of rotation calculation equation but I could not figure out how to change it.
> > Here is the code I used to check with the code you provided to introducing the image shift.
> >
> > clear all;
> > image1 = imread('0001.png');
> >
> > xShift = 0;
> > yShift = 20;
> > translatingElement = translate(strel(1), [yShift xShift]);
> > image2 = imdilate(image1,translatingElement);
> >
> > image1 = image1(1+yShift:end-yShift,1+xShift:end-xShift);
> > % get rid of Infs from the imdilate function
> > image2 = image2(1+yShift:end-yShift,1+xShift:end-xShift);
> >
> > nrad = 128; ntheta = 360; cx = (283/2)+0.5; cy = (290/2)+0.5;
> > % cx & cy for a 283x290 pixels image
> >
> > pim1 = polartrans(image1, nrad, ntheta, cx, cy, 'linear', 'valid');
> >
> > pim2 = polartrans(image2, nrad, ntheta, cx, cy, 'linear', 'valid');
> >
> > pim1 = pim1 - mean(mean(pim1));
> > pim2 = pim2 - mean(mean(pim2));
> >
> > cc_Matrix = xcorr2(pim1, pim2);
> > figure (1);
> > imagesc(cc_Matrix);
> > axis image;
> > [max_cc_Matrix, maxColumn] = max(max(cc_Matrix))
> > [max_cc_Matrix, maxRow] = max(cc_Matrix(:, maxColumn))
> >
> > roiDiam = 20;
> > cc1_Matrix = cc_Matrix(maxRow-roiDiam/2:maxRow+roiDiam/2, maxColumn-roiDiam/2:maxColumn+roiDiam/2);
> > figure (2);
> > imagesc(cc1_Matrix);
> > axis image;
> > [a,b] = find_com(cc1_Matrix) % calling function
> >
> > Angle_of_rotation = (a + maxColumn - length(cc1_Matrix)/2) * 360/ntheta
> >
> > Could you pls have a look of this with any of your random image?
> >
> > Thanks.
> > Darren

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

© The Math Forum at NCTM 1994-2018. All Rights Reserved.