Affine Transformation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Affine Transformation

Gianni Rossi-3

Hi All,

 

I’m new both to this mail-list and to GeoTIFF too.

 

Nevertheless, I’m developing a Cad application which allows the user to pick a desired number of points in a TIFF raster image (thus the application retrieves their raster coordinates) and inputs their corresponding model coordinates. Then the application performs an affine transformation between the two systems and calculates the 4 parameters: X translation, Y translation, scaling factor, rotation angle.

 

So my question is: how do I store this georeferencing data into the original TIFF file so that it becomes a GeoTIFF file?

 

Looking at some documentation, it seems that ModelTransformationTag would do the case, but unfortunately I could not find specification on how to transform my (affine transformation) parameters into its arguments.

 

Another option for me could be to create a TFW file, but also in this case I don’t understand how to convert my affine transformation 4 parameters into the TFW values. Also, Cad software, such as AutoCAD, seems to ignore the second and third lines of a TFW (X/Y rotation).

 

Any help to lead me in the right direction would be greatly appreciated, thanks in advance.

 

Gianni Rossi

Tecnobit S.r.l.

 


_______________________________________________
Geotiff mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/geotiff
Reply | Threaded
Open this post in threaded view
|

Re: Affine Transformation

Frank Warmerdam
Gianni Rossi wrote:

> I’m new both to this mail-list and to GeoTIFF too.
>
> Nevertheless, I’m developing a Cad application which allows the user to
> pick a desired number of points in a TIFF raster image (thus the
> application retrieves their raster coordinates) and inputs their
> corresponding model coordinates. Then the application performs an affine
> transformation between the two systems and calculates the 4 parameters:
> X translation, Y translation, scaling factor, rotation angle.
>
> So my question is: how do I store this georeferencing data into the
> original TIFF file so that it becomes a GeoTIFF file?
>
> Looking at some documentation, it seems that ModelTransformationTag
> would do the case, but unfortunately I could not find specification on
> how to transform my (affine transformation) parameters into its arguments.

Gianni,

I think you would want to write things something like:

            double adfMatrix[16];
       
            memset(adfMatrix,0,sizeof(double) * 16);
       
            adfMatrix[0] = PixelSize * cos(Rotation);
            adfMatrix[1] = PixelSize * sin(Rotation);
            adfMatrix[3] = XOrigin;
            adfMatrix[4] = PixelSize * sin(Rotation);
            adfMatrix[5] = -1.0 * PixelSize * cos(Rotation);
            adfMatrix[7] = YOrigin;
            adfMatrix[15] = 1.0;
       
             TIFFSetField( hTIFF, TIFFTAG_GEOTRANSMATRIX, 16, adfMatrix );


The XOrigin and YOrigin are the top left corner of the image, the
PixelSize is the width/height of a pixel in geo units, and the Rotation
is the rotation angle in radians (if using the C sin/cos functions)
clockwise from straight up.

I may have made a few mistakes but the gist of the solution is here.
The worldfile coefficients are computed similarly though the ordering
is presumably different.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Geotiff mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/geotiff
Reply | Threaded
Open this post in threaded view
|

Re: Affine Transformation

Cody Benkelman
Gianni (and Frank)

I haven't reviewed Frank's response in detail, but I expect he got it
correct for the case of translation, scale & rotation only.  However, I
wanted to express a word of caution - the general form of the affine
transformation allows nonsymmetric terms in X and Y.

In many cases, software implementations of the affine transformation ARE
constrained as Frank shows (such that the image is translated and/or scaled
and/or rotated) but NOT stretched or slanted - but I wanted to make sure you
want to enforce this rigid constraint.  In a general implementation,
selection of multiple tie points or landmarks used to rectify an image into
a new coordinate system can introduce a nonsymmetric transformation.
Depending on the input imagery and output coordinate systems, a nonsymmetric
transformation may be REQUIRED to properly fit the points.

(Of course, there are other transformations besides affine, but I'm assuming
you already understood that.  The affine rectification won't give you a
truly *accurate* output in most cases).

I hope this helps - if it's not clear and you want further information, feel
free to contact me directly.

Cody Benkelman

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Frank Warmerdam
Sent: Saturday, March 14, 2009 9:36 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [Geotiff] Affine Transformation

Gianni Rossi wrote:
> I'm new both to this mail-list and to GeoTIFF too.
>
> Nevertheless, I'm developing a Cad application which allows the user
> to pick a desired number of points in a TIFF raster image (thus the
> application retrieves their raster coordinates) and inputs their
> corresponding model coordinates. Then the application performs an
> affine transformation between the two systems and calculates the 4
parameters:
> X translation, Y translation, scaling factor, rotation angle.
>
> So my question is: how do I store this georeferencing data into the
> original TIFF file so that it becomes a GeoTIFF file?
>
> Looking at some documentation, it seems that ModelTransformationTag
> would do the case, but unfortunately I could not find specification on
> how to transform my (affine transformation) parameters into its arguments.

Gianni,

I think you would want to write things something like:

            double adfMatrix[16];
       
            memset(adfMatrix,0,sizeof(double) * 16);
       
            adfMatrix[0] = PixelSize * cos(Rotation);
            adfMatrix[1] = PixelSize * sin(Rotation);
            adfMatrix[3] = XOrigin;
            adfMatrix[4] = PixelSize * sin(Rotation);
            adfMatrix[5] = -1.0 * PixelSize * cos(Rotation);
            adfMatrix[7] = YOrigin;
            adfMatrix[15] = 1.0;
       
             TIFFSetField( hTIFF, TIFFTAG_GEOTRANSMATRIX, 16, adfMatrix );


The XOrigin and YOrigin are the top left corner of the image, the PixelSize
is the width/height of a pixel in geo units, and the Rotation is the
rotation angle in radians (if using the C sin/cos functions) clockwise from
straight up.

I may have made a few mistakes but the gist of the solution is here.
The worldfile coefficients are computed similarly though the ordering is
presumably different.

Best regards,
--
---------------------------------------+--------------------------------
---------------------------------------+------
I set the clouds in motion - turn up   | Frank Warmerdam,
[hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Geotiff mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/geotiff


_______________________________________________
Geotiff mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/geotiff