Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

write a tfw file and tiff file with matlab

202 views
Skip to first unread message

Quintijn

unread,
Aug 27, 2010, 7:26:07 AM8/27/10
to
Is it possible to write *tfw file in Matlab for a tiff figure created in matlab?

ImageAnalyst

unread,
Aug 27, 2010, 8:17:54 AM8/27/10
to
On Aug 27, 7:26 am, "Quintijn " <q.m.vanag...@student.utwente.nl>
wrote:

> Is it possible to write *tfw file in Matlab for a tiff figure created in matlab?

Huh? What is a TIFF figure? You create a figure, which may have one
or more items on it like axes, text, etc. You can save that figure if
you want but it's not really a "tiff figure created in matlab." It's
just a MATLAB figure until you save it. You can save it in TIFF
format I suppose - see the new Tiff class built into MATLAB starting
in a recent release. I don't know what a *tfw file is. It is not one
of the supported file types of saveas() or imwrite().

Quintijn

unread,
Aug 29, 2010, 7:48:03 AM8/29/10
to
A .tfw file is used to georeference a .tif file. The .tfw file provides real world coordinate information that allows a corresponding .tif file to be correctly positioned on a map or in a mapping system.

I create a tfw in this way but don't know how to get x-scale and y-scale from the tif figure right. (Cx and CY are center point of the tif figure).

Matlabcode:
PMx=???; %Line 1: x-scale. This is the horizontal distance in meters represented by each pixel. So in the above example each pixel is .6 meters wide.
Ry=0; %Line 2: Rotation about y axis.
Rx=0; %Line 3: Rotation about x axis.
PMy=-???; %Line 4: y-scale This is the vertical distance in meters represented by each pixel. So in the above example each pixel is .6 meters tall. Normally negative, because whilst an image has its origin in the top left corner, for Northings and Eastings the origin is normally considered to be the bottom left corner - hence why the scale is normally negative.

LBx = Lplot - Cx; %Line 5: x-reference point. This is the horizontal coordinate (or Easting) of the center of the top left pixel.
LBy = Lplot + Cy; %Line 6: y-reference point. This is the vertical coordinate (or Northing) of the center of the top left pixel.

tfwgoed = [PMx Ry Rx PMy LBx LBy];

fid = fopen('exp.tfw', 'wt');
fprintf(fid, '%6.8f\n', tfwgoed);
fclose(fid);


ImageAnalyst <imagea...@mailinator.com> wrote in message <00d71137-196c-4ed4...@w30g2000yqw.googlegroups.com>...

ImageAnalyst

unread,
Aug 29, 2010, 9:34:52 AM8/29/10
to
I still don't know what you're talking about. Perhaps if you posted
your tiff figure on line somewhere. And I've never used the tfw
format.
Or maybe someone with the mapping toolbox could help you.

Rob Comer

unread,
Aug 29, 2010, 9:00:20 PM8/29/10
to
> And I've never used the tfw format.
> Or maybe someone with the mapping toolbox could help you.

The Mapping Toolbox function worldfilewrite can export a "referencing matrix" to a world file (with a .tfw suffix), but first you have to register your TIFF image to your map coordinate system (eastings and northings) and produce a referencing matrix. The way to do that depends on the specifics of where your image came from in the first place.

The demo "Georeferencing an Image to an Orthotile Base Layer" solves one type of registration problem, and uses worldfilewrite at the end of Step 3. See:

http://www.mathworks.com/products/demos/shipping/map/mapexreg.html?product=MG

Rob Comer
Mapping Toolbox Development
MathWorks

0 new messages