[Math] circle affine transformation

image processingsignal processing

I am trying to convert a region of pixels surrounded by an ellipse into an equivalent stretched circle.This basically means affine transformation. Assume I want to extract the region in light blue surrounded by the yellow ellipse, then find the equivalent circle for further processing. How can I do so using matrix multiplication, addition and subtraction only? Note that the centre of the ellipse may be another point rather than the origin, say (x0,y0). Assume that I have the values of the minor axis, major axis, the centre and the angle of rotation.

enter image description here

What I have in mind is to counter clockwise rotate the region by theta around the centre, then resize the region so that the length of the minor axis == length of major axis, and then rotate clockwise by theta again around the centre. Still, I don't know how to do so.

applying your answer, given in this code:

"

function [xr, yr] = ellipse2circle(x0,y0,a,b,theta, X, Y)

R1=[+cos(theta), +sin(theta), 0;
-sin(theta), +cos(theta), 0;
0, 0, 1];

R2=[+cos(theta), -sin(theta), 0;
+sin(theta), +cos(theta), 0;
0, 0, 1];

T1=[1, 0, -x0; 0, 1, -y0; 0, 0, +1];
T2=[1, 0, +x0; 0, 1, +y0; 0, 0, +1];
D=[1/1, 0, 0; 0, a/b, 0; 0, 0, +1];

M=T2*R2*D*R1*T1;

V=[X, Y, ones(length(X),1)]';
U=M*V;

xr=U(1,:)';
yr=U(2,:)';

"

I got this result:
enter image description here

Best Answer

Assume that you're representing points as triples of real numbers of the form $$ \begin{bmatrix}{x\\y\\1}\end{bmatrix} $$ so that transformations can be described by $3 \times 3$ matrices. Let $\theta$ be the angle from the $x$-axis counterclockwise to the major axis of your ellipse (in your example, $\theta$ is about 45 degrees, or $\pi/4$ radians). Let $a = \cos \theta$ and $b = \sin \theta$, just to save me typing. Let $(c, d)$ be the center point of the ellipse.

Let $$ R_1 = \begin{bmatrix}a & b & 0 \\ -b & a & 0 \\ 0 & 0 & 1 \end{bmatrix}\\ R_2 = \begin{bmatrix}a & -b & 0 \\ b & a & 0 \\ 0 & 0 & 1 \end{bmatrix} $$ and $$ T_1 = \begin{bmatrix}1 & 0 & -c \\ 0 & 1 & -d \\ 0 & 0 & 1\end{bmatrix}\\ T_2 = \begin{bmatrix}1 & 0 & c \\ 0 & 1 & d \\ 0 & 0 & 1\end{bmatrix}\\ $$ and $$ D = \begin{bmatrix} 1 & 0 & 0 \\ 0 & s/t & 0 \\ 0 & 0 & 1 \end{bmatrix} $$ where $s$ and $t$ are the major and minor axis lengths, respectively.

Then build the matrix $$ M = T_2 \cdot R_2 \cdot D \cdot R_1 \cdot T_1 $$ and the transformation $$ \begin{bmatrix}{x\\y\\1}\end{bmatrix} \mapsto M \cdot \begin{bmatrix}{x\\y\\1}\end{bmatrix} $$ will be the one you want.

Basically, reading from right to left in the list of matrices, this

  • moves the ellipse-center to the origin

  • rotates the ellipse clockwise about the origin by angle $\theta$, so that the major axis lines up with the $x$-axis.

  • scales the $y$-axis up so that it's as fat in $y$ as in $x$.

  • rotates counterclockwise by $\theta$.

  • translates the ellipse-center back to where it used to be.

Related Question