IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
# [DocSampleImports]
import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis
# [DocSampleImports]
def readCmdArguments(argv):
# Default parameters values
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
inputImgPath = os.path.join(imagesSamplePath, "blobs_483x348_UInt8.tif")
inputBinImgPath = os.path.join(imagesSamplePath, "blobs_483x348_Binary.tif")
inputFilterFormula = "Area2dMsr > 800"
tmpPath = PyIPSDK.getIPSDKDefaultDirectory(PyIPSDK.eDefaultExternalDirectory.eDED_Tmp)
outputImgPath = os.path.join(tmpPath, "shapeFiltering2dImg.tif")
try:
# Read the command line, the second argument is a string with all the possible options (short version)
# with a ':' if the option requires an argument and the third argument is the set of trings corresponding
# to the long versions of the program options
opts, args = getopt.getopt(argv,"hi:b:o:f:",["inputGreyImgPath=","inputBinImgPath=","outputImgFilePath=","inputFilterFormula="])
except getopt.GetoptError:
print('<application_script_filename> [--inputGreyImgPath <input_grey_image_file_path>] [--inputBinLabImgPath <input_binary_image_file_path>] [--inputFilterFormula <input_filter_formula>] [--outputImgFilePath <output_image_file_path>]')
sys.exit(2)
# Parse the program options
for opt, arg in opts:
if opt == '-h':
print('<application_script_filename> [--inputGreyImgPath <input_grey_image_file_path>] [--inputBinLabImgPath <input_binary_image_file_path>] [--inputFilterFormula <input_filter_formula>] [--outputImgFilePath <output_image_file_path>]')
sys.exit(0)
elif opt in ("-i", "--inputGreyImgPath"):
inputImgPath = arg
elif opt in ("-b", "--inputBinImgPath"):
inputBinImgPath = arg
elif opt in ("-o", "--outputImgFilePath"):
outputImgPath = arg
elif opt in ("-f", "--inputFilterFormula"):
inputFilterFormula = arg
return inputImgPath, outputImgPath, inputBinImgPath, inputFilterFormula
def main(argv):
# [DocSampleDefineArguments]
# retrieve program parameters
inputImgPath, outputImgPath, inputBinImgPath, inputFilterFormula = readCmdArguments(argv)
# [DocSampleDefineArguments]
# [DocSampleLoadImage]
# opening of input image
inGreyImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inBinImg = PyIPSDK.loadTiffImageFile(inputBinImgPath)
# [DocSampleLoadImage]
# [DocSampleProcess]
# shape 2d filtering operation
outImg = shapeanalysis.shapeFiltering2dImg(inBinImg, inGreyImg, inputFilterFormula)
# [DocSampleProcess]
# [DocSampleSaveImage]
# save generated image
print("Writing result in file : " + outputImgPath)
PyIPSDK.saveTiffImageFile(outputImgPath, outImg)
# [DocSampleSaveImage]
if __name__ == "__main__":
main(sys.argv[1:])