IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
# [DocSampleImports]
import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr
# [DocSampleImports]
# [DocSampleDefineArguments]
# define input image path
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
inputImgPath = os.path.join(imagesSamplePath, "Lena_510x509_UInt8.tif")
# define output data path
outputDataPath = PyIPSDK.getIPSDKDefaultDirectory(PyIPSDK.eDefaultExternalDirectory.eDED_Tmp)
refCsvPath = os.path.join(outputDataPath, "ref_histogram.csv")
estimCsvPath = os.path.join(outputDataPath, "estim_histogram.csv")
# [DocSampleDefineArguments]
# [DocSampleLoadImage]
# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
nbTotPixels = inImg.getGeometry().getNbPixels()
# [DocSampleLoadImage]
# [DocSampleApplyOp]
# definition of histogram measure parameters
binMin = 0
binMax = 255
binWidth = 2
histogramMsrParams = PyIPSDK.createHistoMsrParamsWithBinWidth(binMin, binMax, binWidth)
# computation of reference histogram
refHisto = glbmsr.histogramMsr2d(inImg, histogramMsrParams)
# computation of kernel density estimation
kdeDataSet = glbmsr.kernelDensityEstimator2d(inImg)
# extraction of associated histogram
estimHisto = PyIPSDK.generateHistogram(kdeDataSet,
binMin, binMax, binWidth,
nbTotPixels)
# [DocSampleApplyOp]
# [DocSampleSaveData]
# save generated histograms
print("Saving histograms data to directory " + outputDataPath)
PyIPSDK.exportToCsv(refCsvPath, refHisto)
PyIPSDK.exportToCsv(estimCsvPath, estimHisto)
# [DocSampleSaveData]
try:
# [DocPlotResults]
# plot histogram results
import matplotlib.pyplot as plt
refPlot, = plt.plot(refHisto.getBinMeanColl(), refHisto.frequencies, 'g+-', label="Reference")
estimPlot, = plt.plot(estimHisto.getBinMeanColl(), estimHisto.frequencies, 'ro-', label="Estimation")
plt.title("Image histograms")
plt.xlabel('Bin mean')
plt.ylabel('Population')
plt.legend(handles=[refPlot, estimPlot])
plt.grid(True)
plt.show()
# [DocPlotResults]
except:
print("This part of sample requires matplotlib to be executed.")