Shape File From Raster

[vc_row][vc_column width=”1/1″][vc_column_text]

How to create a shape-file from raster to exactly match irregular image boundary.

In my case I want to get rid of the extra (black) area (fig. shown at the end of this post) to reduce the file dimensions, to be able to use images in PhotoMod (demo) software for mosaicing tiles together. As the demo software is limited to 20 Mega pixels per image and rectified image exceeds that limit if flight line is (rotated) as rotation increases the bounding rectangle, which results in increased image X-Y size.

(Entire process can be done in ArcMap too, but I like to use Gdal (free software) as much as possible.)

Here I will explain how to create the above mentioned shape-file using Gdal & ArcMap.

First step is to convert all non-zero digital numbers of a raster to “0 & 1″

For this conversion I use Gdal Batch Commander and enter the following command in parameters field…
“-co compress=lzw -b 1 -ot byte 0 -a_no-data 0 -scale 1 1″.

This will create a new raster with all non-zero (except no-data,0) values converted to “1” (You can use any number in place of 1).

Command line parameters explained :-

  1. -co compress=lzw it to compress the generated tiffs with losseless LZW compression.
  2. -b 1 option is for using only first band, just to save time by not reading all the bands in MS imagery.
  3. -ot byte will create 8-bit raster.
  4. -a_nodata 0 specifies nodata value for the input band. This one is not shown is figure below, so don’t skip it. As this parameter helps ArcMap to ignore outer rectangle (black area) for its shapefile generation routine.
  5. -scale 1 1 will convert all non-zero pixel values to 1.

gdal batch commander convert raster to 0 & 1

Second step is to convert “0 & 1″ image to shape file.

In ArcMap you can choose “Raster to Polygon” tool to create shapefile. Use ArcMap’s model builder to create a shape file from all the newly created tiffs (with 0 & 1 as pixel values for no-data and data areas respectively). Below is a screenshot of model builder that I used to convert 0&1 tiff to shape file.
Note: Check simplify polygon option in “Raster to Polygon” window.

ArcMap model to convert tiffs (0&1) to shape-file. Don't forget to check simplify polygons option in Raster to Polygon dialog.

Resulting shape file (a yellow polygon) is produced after running Gdal_translate & ArcMap.

2015_04_08_16_31_06_Untitled - ArcMap

Now I can use the shape-file to crop the raster to the newly generated polygon and get rid of the extra black area.



Lens Distortion Correction for FLIR camera

General approach for lens distortion correction, is to take a picture of a checker board from the desired camera. Then import the image in lens correction software and let it figure out how much the straight edges of the checker board got distorted, then the lens correction software finds out necessary correction to straighten distorted edges and finally give a lens distortion equation.

Since a regular checker board printout will have same temperatures for the entire surface, it will be difficult to capture a checker board image with this approach.

Another option is to make checker board of high reflective material(silver foil etc.), this will result in much darker alternate (metallic) checkers. But this approach requires a lot of design work.

I devised another approach as follows:-

I review the frames and find out several images with following properties:-

  • Very flat surface.
  • Lots of details e.g. intersection, roads, sharp edged features etc.
  • Close to zero pitch & roll values from orientation data.

Note: I have to do this only once for a particular lens.

  1. Then select one of the image that fits best to the above criteria. And rectify it to the ortho rectified MS mosaic or recent NAIP.
  2. Then rectify (at polynomial order 1) the above (step 1) image to original un-rectified image. This will strip off the geo-referencing information. This leaves us with an image which is  corrected for lens distortion and have same co-ordinate system as raw (input) image.
  3. Use this jpg as a basemap for the raw (distorted) images and rectify it by putting several tie points in ArcMap and save the tie point file. This tie point file is your lens calibration model.
  4. Now all the 16 bit tiff’s can be corrected in batch mode by using the tie point file generated above.

Arcmap Ortho Rectification Using NAIP.

An orthophoto, orthophotograph or orthoimage is an aerial photograph, geometrically corrected (“orthorectified”) such that the scale is uniform (Wikipedia)

ArcMap can be used to orto rectify aerial images to a NAIP imagery as a basemap.

I usually ortho rectify thermal imagery using this method, as we don’t have orientation information for the acquired thermal images.

These are the steps that I follow for creating ortho-mosaic from thermal imagery:-

  1. Extract tiffs (32 bit)  tiffs from the raw sequence file recorded by FLIR SC640 thermal camera.
  2. Convert 32bit floating tiffs to 16 bit unsigned integer format, as later I will use the rectified tiffs in PhotoMod for fine adjustments.
  3. Perform batch lens distortion correction on each frame.
  4. First download the desired base-map (NAIP Ortho imagery) from Geo Spatial Data Gateway or if I have a high resolution and more recent ortho-mosaic I can use that too.
  5. In case you have downloaded multiple tiles to cover the area of interest, you might want to mosaic the tiles together. I have discovered a quick way to mosaic tiles using gdal.
  6. Open the basemap (NAIP) image in ArcMap.
  7. Add a thermal image (one we corrected for lens distortion and converted to 16 bit) in ArcMap and
  8. Make sure Georeferencing toolbar is enabled, else enable it from customize>>toolbar menu.
  9. Watch the following video for detailed steps to create tie points and rectify image.[spacer height=”20px”]