Take me to pcigeomatics.com

PCI Geomatics Help Center

How can we help you today?

Batch Processing Raw Input

PCI Geomatics -

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

	PCI Geomatics(C) - Applying Image Enhacements with Batch Processing
	
*************************************************************************'''

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

# This script loops through files in a folder and performs a task on each file. All of the inputs are set by the end user through raw_input

# -------------------------------
# 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

# The following locale settings are used to ensure that Python is configured
# the same way as PCI's C/C++ code.  
import locale
locale.setlocale(locale.LC_ALL, "")
locale.setlocale(locale.LC_NUMERIC, "C")

# ---------------------
# Set File variables
# ---------------------
print ""
print "Setting folder path..."

InFolder = raw_input("Please state your input folder path: ") # User will enter pathname

# ----------------------------------------------------
# Create list of files to loop through from InFolder
# ----------------------------------------------------
print "Creating list of valid files..."
# 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 "Entering raw input information for PCIMOD algorithm..."

# Bring the raw_input definitions to outside the loop. Keeping these definitions within the
# loop will force the user to enter the information each time the loop iterates
pciop_raw = raw_input("Specify whether to add, delete or compress channels (ADD, DEL, COM): ")   
pcival_raw = eval(raw_input("Specifiy the number of 8bit, 16bit signed, 16bit unsigned\
and/or 32bit real channels you want to add  (eg. [3,0,0,0] for 3 8bit): "))   

# Run PCIMOD algorithm with each file listed in input_files_list
print ""
print "Beginning the PCIMOD algorithm to create add three 8 bit channels"

for pix in input_files_list:
        # Using the _raw variables from above, define each of the required arguments
        file = pix                         # input file
        pciop = pciop_raw      # Specify whether to add, delete or compress channels
        pcival = pcival_raw    # 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 "Channels added"


# ----------------------------------------------------------------------------------
# Use FUN algorithm to create look up tables (LUTs) to save enhancement information 
# ----------------------------------------------------------------------------------
print ""
print "Entering raw input information for FUN algorithm..."


func_raw = raw_input("Enter the enhacement you wish to apply (EQUA, NORM, MATC, INFR, ADAP): ")   
dbic_raw = eval(raw_input("List the bands you wish to create LUTs for (eg. [1,2,3]): "))   
dbsn_raw = raw_input("Set a name for the segments: ")          
dbsd_raw = raw_input("Set a name for the LUTs: ")

print ""
print "Beginning the FUN algorithm to create LUTs"
	
for pix in input_files_list:
	
        # Using the _raw variables from above, define each of the required arguments
        file = pix     
        func = func_raw          # equalization is chosen as the enhancement type
        dbic = dbic_raw          # specifies which bands to create look-up tables for
        dblut = []               # if left blank LUTs are saved to new LUT channels
        dbsn = dbsn_raw          # segment name 
        dbsd = dbsd_raw          # name for the look-up tables 
        ostr = []                # stretch range 
        sdpt = []                # only used in normalization enhacement
        trim = []                # Ammount of tail trimming 
        mask = []                # Specifies specific area 
        dbhc = []                # input histogram match channel
        lasc = []                # Last segment created

        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 "LUTs created"


# ----------------------------------------------------------------------------------
# Use LUT algorithm to apply LUTs and save to new channels
# ----------------------------------------------------------------------------------
print ""
print "Entering raw input information for LUT algorithm..."

dbic_raw = eval(raw_input("Specifiy the original input bands to be enhanced (eg. [1,2,3]): "))
dboc_raw = eval(raw_input("Specifiy the channels you wish to save enhacements to (eg. [4,5,6]): "))

print ""
print "Beginning the LUT algorithm to apply LUTs"

for pix in input_files_list:
        
        # Using the _raw variables from above, define each of the required arguments
        file = pix 
        dbic = dbic_raw      # Original input bands to be enhanced 
        dblut = lasc         # Look up tables created in FUN  
        dboc = dboc_raw      # 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 "Enhancements applied"
print ""
print "All Processing Complete"


Have more questions? Submit a request

Comments

Powered by Zendesk