UAV Ortho Color Balancing in PCI

Ortho Color balancing for large UAV ortho mosaics can be a challenging task. Usually you start to get into troubles when illumination conditions are quickly changing – at sub-optimal conditions with clouds  and low illumination condition in spring or autumn.  color balancing in Agisoft does a good job but sometime we need more – here a hot spot correction and global adaption is sometimes needed. PCIs Orthoengine does a great job here.

This is a small python script that uses the ortho corrected geotiff files from Agisoft and applies a local and global correction.

 

1. Head section of a Python PCI script

Here we  load some PCI libraries.

print ""
print "***************************************************************"
print ""
print " -= SHESE 4 hainich ortho processing =-"
print " workflow"
print " Last modified 24112018"
print ""
print "***************************************************************"
# This script runs the following PPFs in a top-down sequence and generates a 
# ortho mosaic based on the input ortho images exported from AGISOFT Photoscan.
# All orthos must have the same georef and resolution. 
# 1. mosrep
# 2. mosdef
# 3. mosrun
import sys 
import os
import pci
import fnmatch
from pci.fun import *
from pci.lut import *
from pci.fimport import fimport
from pci.pcimod import pcimod
from pci.model import model
from pci.exceptions import *
from pci.ortho import ortho
from pci.mosprep import mosprep
from pci.mosdef import mosdef
from pci.mosrun import mosrun
from pci.exceptions import PCIException
The comments are defined using a hash sign - you can also put these comments directly behind any coded line

2. The xml section of the script that defines the processing parameters

where xml files are defined – you usually want that from the user and not hard coded into your script – so f.e. using the following expression the user would have to start the script by typing:

python pythonscriptname /dir/where/the/files/are

to start the script and to include the “InFolder” string (in this example). We later use “InFolder” to place the string into pathname.

mfile = r"W:\work-hainich\Hainich08-2018\exported-orthofiles"
silfile = r"W:\work-hainich\Hainich08-2018\exported-orthofiles\mosaic.xml"
nodatval = [0]
normaliz = "HotSpot" #HotSpot method often useful for airphoto imagery
balspec = "BUNDLE"
cutmthd = "minsqdiff"

try:
 mosprep(mfile, silfile, nodatval, "", normaliz,
 balspec, "", "", [], cutmthd)
except PCIException, e:
 print e
except Exception, e:
 print e

## Create Mosaic Definition XML file to
silfile = r"W:\work-hainich\Hainich08-2018\exported-orthofiles\mosaic.xml"
mdfile = r"W:\work-hainich\Hainich08-2018\exported-orthofiles\mosaicdef.xml"
dbic = [1,2,3]
tispec = ""
tipostrn = ""
mapunits= "UTM 32 D000"
pxszout= [0.03]
blend = [5]
nodata = [0]
ftype = "PIX"
foptions = ""
try:
 mosdef(silfile, mdfile, dbic, tispec, tipostrn, mapunits, pxszout, blend, nodata, ftype, foptions)
except PCIException, e:
 print e
except Exception, e:
 print e

## Finally create the full resolution mosaic
outdir = r"W:\work-hainich\Hainich08-2018\exported-orthofiles"
crsrcmap = ""

try:
 mosrun(silfile, mdfile, outdir, "", crsrcmap,
 "", "", "", "BILIN")
except PCIException, e:
 print e
except Exception, e:
 print e