Take me to pcigeomatics.com

PCI Geomatics Help Center

How can we help you today?

Batch Processing

PCI Geomatics -

'''**********************************************************

	PCI Geomatics(C) - Applying Image Enhacements
	
**********************************************************'''

print ""
print ""
print "***************************************************************"
print ""
print "       -= PCI Geomatics(C) =-"
print "     Applying Image Enhacements"
print ""
print "***************************************************************"

# This script loops through files in a folder and performs algorithms with each file.

# -------------------------------
# Import the required algorithms
# -------------------------------
print "Importing Libraries"
print ""

from pci.fun import *
from pci.lut import *
from pci.pcimod import *
from pci.exceptions import *

import sys      # These two libraries are required to extract file names from folders
import os
import fnmatch

import locale
locale.setlocale(locale.LC_ALL, "")
locale.setlocale(locale.LC_NUMERIC, "C")


# ---------------------
# Set File variables
# ---------------------

# This folder can be a folder that includes other folders with images
InFolder = r'W:\2014_Tutorials\Python\Data\GeomaticaPythonInput'

# ----------------------------------------------------
# Create list of files to loop through from InFolder
# ----------------------------------------------------

# This line is a wildcard filter. In this case only tif files will be used
file_filter = "*.pix"  

# This list will become populated with the full pathnames of each file in InFolder
input_files_list = [] 

# os.walk searches a directory tree and produces the file name of any file it encounters
# r is the main directory
# d is any subdirectory within r
# f image file names within r
for r,d,f in os.walk(InFolder):  
    for file in fnmatch.filter(f, file_filter): # fnmatch.filter filters out non .pix files 
        print "found valid input file: ", file
        input_files_list.append(os.path.join(r,file)) # The file name and full path are added to input_files_list

# ----------------------------------------------------------------------------------
# Use PCIMOD algorithm to add three 8bit unsigned channels to save enhanced bands 
# ----------------------------------------------------------------------------------
print ""
print "Beginning the PCIMOD algorithm to add three 8 bit channels"

for pix in input_files_list:
	file = pix         # input file
	pciop = 'ADD'      # Specify whether to add, delete or compress channels
	pcival = [3,0,0,0] # These numbers represent how many 8bit, 16bit signed, 16bit unsigned
			   # or 32bit real channels you want to add
	try: pcimod(file, pciop, pcival)
	except PCIException, e: print e
	except Exception, e: print e
print "PCIMOD Algorithm Complete. Channels added."   
 
 

# ----------------------------------------------------------------------------------
# Use FUN algorithm to create look up tables (LUTs) to save enhancement information 
# ----------------------------------------------------------------------------------
print ""
print "Beginning the FUN algorithm to create LUTs"

# Loop through each file in the InFolder
for pix in input_files_list: 
	# each of the arguments for FUN are listed in the order specified in the help.
	file = pix     
	func = 'EQUA'                  # equalization is chosen as the enhancement type
	dbic = [1,2,3]                 # specifies which bands you want to create look-up tables for
	dblut = []                     # if left blank LUTs are saved to new LUT channels
	dbsn = u"Equa LUT"             # LUT segment name 
	dbsd = "Equalization LUTs"     # LUT segment descriptions 
	ostr = []     		       # stretch range 
	sdpt = []     		       # only used in normalization enhacement
	trim = []    		       # Ammount of tail trimming 
	mask = []      		       # Specifies specific area 
	dbhc = []    		       # input histogram match channel          
	lasc = []                      # asigned number of new LUT segment after FUN is run  

	try: fun(file, func, dbic, dblut, dbsn, dbsd, ostr, sdpt, trim, mask, dbhc, lasc)
	except PCIException, e: print e
	except Exception, e: print e
print "FUN Algorithm Complete. LUTs created"
  
  
# ----------------------------------------------------------------------------------
# Use LUT algorithm to apply LUTs and save to new channels
# ----------------------------------------------------------------------------------
print ""
print "Beginning the LUT algorithm to apply LUTs"

for pix in input_files_list:
	
	file = pix 
	dbic = [1,2,3]      # Original input bands to be enhanced 
	dblut = lasc        # Look up tables created in FUN. lasc was populated after fun was run  
	dboc = [4,5,6]      # Three new 8bit bands created in PCIMOD
	mask = []           # Defines the area that will be processed (left as default)

	try: lut(file, dbic, dblut, dboc, mask)
	except PCIException, e: print e
	except Exception, e: print e

print "LUT Algorithm Complete. Enhancements applied"
print ""
print "All Processing Complete"
Have more questions? Submit a request

Comments

Powered by Zendesk