Posts Tagged 'format'

By the way, what is an image file format?

Some beginners would like to ask but do not dare:

What is a file format?

To start, let’s say it is only the way the data are written in your file. In principle, it should not affect the image itself.

Ok, but an image is only a 2D array (the image is a rectangle), with optionally a third dimension to store bands. A very straightforward way of saving this data in a file is simply to copy the matrix into the file in a very plain way: 1st pixel, 2nd pixel, 3rd pixel, etc up to the last pixel of the first line, then continue on the next line, and so on to the end of the image. This is what does the Envi format. When you have bands, you can even choose if you want to write all the bands values of the same pixel in a row, or write the image of the first band first, then append the second band, etc. In any case, you’ve got something that is very similar to a copy of the computer memory where the file as to be placed when it is read.

Pages: 1 2 3

What format is this file?

Have you ever wondered what is really the file format of an image? Or what are the 4 corners coordinates, or the projection? You can get the answer in a single command line. Say we want to know more about an image name africa.img. Actually the file extension,.img can not be considered as a trustful indication of the real format inside the image, since you can change it as you like. Extensions are only a file naming convention and have nothing to do with the data really written in the file (and the format is much more HOW is written the data).

The command gdalinfo accepts several parameters, to know them simply type:


and you get a list of optional parameters (which can change in future versions), the only mandatory parameter being the filename (datasetname):

Usage: gdalinfo [--help-general] [-mm] [-stats] [-nogcp] [-nomd]
[-mdd domain]* datasetname

To get accurate information on the command line, have a look on

Pages: 1 2 3

Changing geospatial images file format

In the field of Earth Observation, a wide range of file formats exists. Many of them come from software which imposed their home made formats, like Erdas-Imagine HFA files or Envi/IDL file format, while others where created by reasearch groups like HDF made by the HDF group of the University of Illinois or geotiff which is an effort of the open source community in which many Universities or companies are involved.

Unfortunately, it comes that the file format with which you are provided is not necessarily the one you wish to have, whether it is not supported by your software or that it does not match some database requirements.

To make these changes I use gdal_translate which is one of many commands available from FWTools package or from a gdal installation. First install gdal, or better FWTools on your PC, and get some data. We will use the commands from the shell, ms-dos or linux shell (bash for example), the path to your gdal commands (or FWTools commands) must be correctly set. To know if everything works, run the FWTools shell (or open an ms-dos box) or go to your linux prompt and type:
The command should answer a long text like this one:

gdal_translate help and list of formats

gdal_translate help and list of formats

The first section of the text gives you the list of options you can use along with the command line, following the classical convention: parameters between brackets [ ] are optional, braces { } give you a list of choices, parameters without brackets [ ] are mandatory.

Hence, the minimal command you can invoke is
gdal_translate file_in file_out
which will export your input file (in any supported format) into the default output (which is geotiff).
Let’s say you want to transform an Erdas Imagine file named africa.img into a geotiff image named export_africa.tif, you simply write
gdal_translate africa.img export_africa.tif

gdal_translate guess the input format, you do not even need to know it!

Now you can use the -of option to define the export format. Say you want to export to Windisp file format (which name is IDA). Say you want the output image in IDA format to be named africa.ida, you have to write:
gdal_translate -of IDA africa.img africa.ida

Of course, it works only if you input image is in Bytes (8bits) since IDA format only support 8bits.

A short list of format (a reminder) is visible if you type
To see the exhaustive list of formats, type
gdal_translate --formats
The list is rather impressive and tells you if you can read only (ro) or read and write (rw) or even read, write and update existing files (rw+).
gdal_translate --formats | more
to pause when displaying the information (press ENTER to move forward by one line or space to move by one page). You can see that you can read, write and update geotiff or Erdas Imagine formats
GTiff (rw+): GeoTIFF
HFA (rw+): Erdas Imagine Images (.img)
, you can read and write ERMapper Compressed Wavelets images
ECW (rw): ERMapper Compressed Wavelets but only read HDF5 images
HDF5 (ro): Hierarchical Data Format Release 5

You can find more details about formats on the gdal page.

Do not forget that some formats, like windisp IDA, do not support all type of data. For example windisp IDA only support Bytes. When exporting TO this format, you must be sure that your original data can be stored on Bytes, else you need to apply a rescaling of the data.

In next posts, we will see how to use the other options.