meetri
meetri

Reputation: 2186

find corresponding point in a rotated image

I need help transforming a selected point in the Rotated View back to it's corresponding point in the original Image. So for example if I clicked in the upper left ( 0,0 ) in the rotated view, it should correspond to (0,1280) in the original image.

Extra points for a solution that works regardless of the rotation.

Original Image ( 1920 x 1280 )     Rotated View ( for display on phone )
+----------------------------+     +-----------------+
|(0,0)                       |     |(0,0)            |  ( 1280 x 1920 )
|                            |     |                 |
|                            |     |       x         |
|    x                       |     |    ( click )    |
|    ( what is this point )  |     |                 |
|                            |     |                 |
|                            |     |                 |
+----------------------------+     |                 |
                      (1920,1280)  |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   +-----------------+
                                                      (1280,1920)

UPDATED


    /*
    This is how I build the matrix used to perform the initial rotation from the original to     the rotated image. This matrix also includes scaling 

    Code base: Android/Java
    bitmap ( bitmap i'm scaling/rotating )
    canvas ( the canvas being drawn to )

    Note: bitmap is in landscape mode / canvas is in portrait

    */

    Matrix matrix = new Matrix();
    float centerX = canvas.getWidth() >> 1;
    float centerY = canvas.getHeight() >> 1;

    rAngle = 90;
    scaleH = ((float) canvas.getHeight()) / bitmap.getWidth();
    scaleW = ((float) canvas.getWidth()) / bitmap.getHeight();

    scaler.preScale(scaleH, scaleW);
    scaler.postRotate(rAngle, centerY, centerX);

    float nx = (canvas.getHeight() - canvas.getWidth()) / 2;
    scaler.postTranslate(-nx, nx);

    canvas.drawBitmap(bitmap,scaler,null);

I'm hardly a math guy, so any hand holding will be appreciated. :)

Upvotes: 1

Views: 293

Answers (1)

beaker
beaker

Reputation: 16801

Subscript O indicates coordinates in the original frame and subscript R in the rotated frame:

XO = YR
YO = maxXR - XR

The four corners of the frame give us:

For top-left in the rotated frame (0,0)

XO = 0
YO = 1279 - 0 = 1279
(0, 1279)

For top-right, (1279, 0):

XO = 0
YO = 1279 - 1279 = 0
(0, 0)

For bottom-left, (0, 1919):

XO = 1919
YO = 1279 - 0 = 1279
(1919, 1279)

For bottom-right, (1279, 1919):

XO = 1919
YO = 1279 - 1279 = 0
(1919, 0)

Upvotes: 1

Related Questions