[gdal-dev] Need help converting a geotiff file to jpg/tiff/bmp

Benjamin R Welton benjamin.r.welton at wmich.edu
Mon Dec 1 10:38:06 EST 2008


Thanks for your quick response.

The geotiff files that i am trying to convert are single band. I am not looking to create a false three color tiff from these images i only need to have a gray scale representation of the images.

Iv had a little bit of time to look over the documentation on the VRT Driver. It looks like i could essentially use the same template for all of the images with only the filename and xsize/ysize altered for each file. Ill make an attempt to do the conversion using the VRT files and see if i can get the image i want by using that process. One quick question though, is there any file size or area limits on how large the VRT could do a conversion for? The files that i am doing this conversion on are not really large (2000x4500 pixels max) so i am assuming that it will be fine.

Thanks for your help,
Ben 

----- Original Message -----
From: Frank Warmerdam <warmerdam at pobox.com>
Date: Wednesday, November 26, 2008 9:31 pm
Subject: Re: [gdal-dev] Need help converting a geotiff file to jpg/tiff/bmp

> 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 
> appliesscaling and a conversion of data type; however, this may be 
> fairlyinvolved.
> 
> I'm also concerned that you have a one band file and that you are 
> hopingfor 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.comlight and sound - activate the windows | 
> http://pobox.com/~warmerdamand watch the world go round - Rush    | 
> Geospatial Programmer for Rent
> 
> 



More information about the gdal-dev mailing list