Crop Images Using Gdal Batch Commander

I align NIR, Red image bands to Green band in order to create false color composite in ArcMap. Since image alignment/stacking process shifts NIR & Red bands, so they match perfectly to the Green band. This causes dark colored borders and there is no data from at least one band. This causes problems when TerraPhoto tries to balance color of the overlapping images. This results in improper color balancing. I use Gdal Batch Commander to fix this issue as follows:-



There is as dark stripe on all sides of the image, specially left and top strips are clearly visible in the image above. To crop the the side strips I use “IrfanView software”, by drawing bounding box in such a way that the box excludes side borders. IrfanView’s title bar display’s the top left coordinates (28,31), where crop needs to initiate and the width and height (1983,2000) of the crop box (new image size). Then I use above cropping information in Gdal Batch Commander as follows:-




Gdal Batch Commander

Gdal Batch CommanderSince I use several software in Orhto-Rectification workflow and these software have their strengths and weaknesses. I switch between software to achieve best results. For instance, I rectify thermal imagery in ArcMap, since it has a very robust interface for rectification. But for stitching (mosaicking) images together I use PhotoMod software as it has very good module for aligning (fine-adjustments) of rectified images. But it does not support 32bit (float) images. I use this utility to convert 32-bit float images to 16-bit images in order to use in PhotoMosaic.

I use this utility to speed up my repeating task, by running them in batch mode, e.g.:-

  • To crop borders from the stacked (NIR, Red & Green) imagery.
  • Create shapefile from raster with non-rectangular boundary, which exactly follows the raster edges.
  • Resample images at lower resolution for quick overviewing.
  • Change from one file format to another e.g.   .img to .tif etc.

This utility can be used in numerous other ways. This utility is not limited to gdal_translate, it can be used with any other gdal command line executable which accepts parameters in similar way.

Tip: You might want to download and keep all Gdal executables and dll’s in “c:Gdal” folder for Gdal Batch Commander to function properly.

Convert Float 32 bit to 16 bit using gdal commander

I use PhotoMosaic (a module of PhotoMod) software for stitching and color balancing rectified images. And it doesn’t support images from FLIR camera, since they are in 32 bit (floating point) tiffs. Therefore I have to convert all 32 bit images to 16 bit format to be able to use them in Photomod.

I use “gdal_translate -ot Uint16 -scale -40 120 0 65535 inp.tif out.tif” to convert thermal images which had original temperature range of -40 to 120 C to 16bit digital number ranging from 0 to 65535.  In Gdal Batch Commander I will just enter the underlined part of the above command and select all images and execute the same command on all the selected images.

Gdal Batch Commander float to 16 bit

Once mosacing process is complete, I convert 16bit mosaic back to 32bit float pixel values by using “gdal_translate -ot Uint16 -scale 0 65535 -40 120 inp.tif out.tif” command.

Best thing about gdal is that even after converting the pixel values from float 32 to 16 bit, still maintains geographical location information. And I can just use simple command line switches and convert hundreds of rectified tiff in single Gdal Batch Commander run.