0

I have read somewhere (but i do not remember where exactly) it was possible to rotate pixels of an image by applying a single matrix (just additions and multiplication).

This was done without sinus and cosinus functions.

I am wondering if i had a dream or if this is really possible...

Thanks

Bob5421
  • 7,757
  • 14
  • 81
  • 175

3 Answers3

1

3x3 transform matrices are the standard abstraction in 2D graphics work. See: https://en.m.wikipedia.org/wiki/Transformation_matrix . Whether this avoids sine and cosine is a bit up for debate as one typically uses those trigonometric functions to construct a rotation matrix if starting from an angle.

Zalman Stern
  • 3,161
  • 12
  • 18
  • Do you have a C++ sample source code which does by hand the matrix calculation applying to the image ? Every code i find works with opencv so i do not see how it works in internal. Thanks – Bob5421 Oct 09 '17 at 06:56
0

Yes, and no.

You apply a rotation with a matrix, as this is an affine transformation (https://en.wikipedia.org/wiki/Affine_transformation).

But if the rotation amplitude is specified by an angle, you can't avoid the use of the trigonometric functions to evaluate the coefficients.

A last remark: this is completely harmless, why worry ?

0

In graphics we usually use homogenuous transform matrices for tasks like this. So the algo is like this:

  1. create transform matrix

    holding all the transforms you want. For 2D it is 3x3 homogenuous transform matrix or 2x2 rotation matrix (no translations).

  2. process all destination pixels

    basically copy pixel from source to destination image, but the loops are looping every destination pixel (to avoid rounding holes). So let the loop goes through (x,y) so you just copy pixels ...

    dst[y][x] = src[y'][x']
    

    where:

    (x',y') = Matrix2x2 * (x,y)
    

    or

    (x',y',w) = Matrix3x3 * (x,y,1)
    

It does not matter if you use 2x2 or 3x3 matrix or hardcoded multiplication (as in example) see:

but you need to use sin,cos for the matrix values (once per rotation). The only rotation without sin,cos is rotation by 90 deg Where:

(x',y') = (-y,x)

or:

(x',y') = (y,-x)
Spektre
  • 49,595
  • 11
  • 110
  • 380