[Geotiff] Affine Transformation

Cody Benkelman benkelman at yahoo.com
Sat Mar 14 21:25:10 PDT 2009


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: geotiff-bounces at lists.maptools.org
[mailto:geotiff-bounces at lists.maptools.org] On Behalf Of Frank Warmerdam
Sent: Saturday, March 14, 2009 9:36 PM
To: g.rossi at tecnobitmail.com
Cc: geotiff at lists.maptools.org
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,
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Geotiff mailing list
Geotiff at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/geotiff





More information about the Geotiff mailing list