[gdal-dev] Need help converting a geotiff file to jpg/tiff/bmp
Frank Warmerdam
warmerdam at pobox.com
Wed Nov 26 21:31:36 EST 2008
Benjamin Welton wrote:
> Hello everyone,
>
> Im quite new to using GDAL and what i would like to do is convert a
> geotiff file to a standard jpeg/tiff/bmp image file so that it can be
> viewed by any standard image reading software (ideally i would like to
> be able to display said image using wxPython) . Every time i try to
> convert an image it creates ether an image that is not compatible with
> some basic image viewing/editing tools or it creates and image that is
> monochrome and all detail of the image is lost. What would be the best
> way to go about creating a standard jpeg/tiff/bmp so that it can be
> viewed in basic image editing/viewing tools? The geotiff is a int16
> datatype file and i do not really need to keep any of the actual
> georeferencing information contained in the geotiff file.
>
> Here is the python code that i am using to convert the image to a
> standard tiff file:
> dataset = gdal.Open( "C:\\Geotiff.tif", GA_ReadOnly )
> format = "GTiff"
> driver = gdal.GetDriverByName( format )
> metadata = driver.GetMetadata()
> dst_ds = driver.CreateCopy("C:\\Example.tiff",dataset,0,
> ["PROFILE=BASELINE"] )
>
> Any help anyone could provide to me would be great.
Ben,
How many bands does the int16 geotiff file have?
Generally, the hard part here is converting the int16 image pixels to
Byte to produce a fairly universal output file. The proper way to do
this would likely be to create an intermediate virtual file that applies
scaling and a conversion of data type; however, this may be fairly
involved.
I'm also concerned that you have a one band file and that you are hoping
for colorization based on some undefined scheme, but I'll need to know
more about the source file to know the answer to that.
The following VRT file demonstrates using a ComplexSource to rescale
an image from 16bit to 8bit. You could construct something similar
to use in your Python (substituting in appropriate sizes, extra bands,
etc).
<VRTDataset rasterXSize="512" rasterYSize="512">
<VRTRasterBand dataType="Byte" band="1">
<ComplexSource>
<SourceFilename relativeToVRT="1">utm.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512"/>
<DstRect xOff="0" yOff="0" xSize="512" ySize="512"/>
<ScaleOffset>0</ScaleOffset>
<ScaleRatio>0.085</ScaleRatio>
</ComplexSource>
</VRTRasterBand>
</VRTDataset>
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
More information about the gdal-dev
mailing list