import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLBinarization as bin
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
inputImgPath = os.path.join(imagesSamplePath, "Lena_510x509_UInt8.tif")
tmpPath = PyIPSDK.getIPSDKDefaultDirectory(PyIPSDK.eDefaultExternalDirectory.eDED_Tmp)
outputImgPath = os.path.join(tmpPath, "otsu.tif")
try:
opts, args = getopt.getopt(argv,"hi:o:",["inputImgFilePath=","outputImgFilePath="])
except getopt.GetoptError:
print('<application_script_filename> [--inputImgFilePath <input_image_file_path>] [--outputImgFilePath <output_image_file_path>]')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('<application_script_filename> [--inputImgFilePath <input_image_file_path>] [--outputImgFilePath <output_image_file_path>]')
sys.exit(0)
elif opt in ("-i", "--inputImgFilePath"):
inputImgPath = arg
elif opt in ("-o", "--outputImgFilePath"):
outputImgPath = arg
return inputImgPath, outputImgPath
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
outOtsu = bin.otsuThresholdImg(inImg)
outImg = outOtsu[0]
outThreshold = outOtsu[1]
print("Writing result in file : " + outputImgPath + " (estimated threshold = " + str(outThreshold) + ")")
PyIPSDK.saveTiffImageFile(outputImgPath, outImg)
if __name__ == "__main__":