IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

module demonstrating how to achieve a processing duration benchmark for an IPSDK library algorithm More...

module demonstrating how to achieve a processing duration benchmark for an IPSDK library algorithm

Overview

This python application computes the local entropy image on a 2d input image loaded from a given input TIFF file, and saves the result in a given TIFF file.

See also
Local entropy 2d algorithm
Note
The used processing function (local entropy 2d in that case) can be replaced by any other IPSDK algorithm that the user would like to benchmark.

Usage

The application can be called through a command line as follows:

   <application_script_filename> [--inputImgFilePath <input_image_file_path>] [--outputImgFilePath <output_image_file_path>] [--inHalfKnlSizeX <input_half_kernel_x_size_value>] [--inHalfKnlSizeY <input_half_kernel_y_size_value>] [--inOptNbClasses <input_number_of_classes>]
     
   Arguments:
      --inputImgFilePath  optional; specifies the name of the TIFF file, from
                          which the 2d input image will be loaded; if not 
                          specified by the user, the input image is loaded from
                          file 
                          <DEV_ROOT>/data/Sample/images/Lena_510x509_UInt8.tif
                          
      --outputImgFilePath optional; specifies the name of the TIFF file, in
                          which the 2d output image resulting from entropy
                          computation will be saved; if not specified by the
                          user, the output image is saved in file
                          <TEMPORARY_IPSDK_DIR>/Sample/benchmark.tif
                          
      --inHalfKnlSizeX    optional; specifies the half size, along x axis, of
                          kernel used to compute the entropy image; default
                          value equals to 3
                          
      --inHalfKnlSizeY    optional; specifies the half size, along y axis, of
                          kernel used to compute the entropy image; default
                          value equals to 3

      --inOptNbClasses    optional; specifies the number of classes used to
                          compute the entropy image; default
                          value equals to 16

Source code documentation

We start by importing all necessary libraries:

import os
import sys, getopt
import time
import PyIPSDK
import PyIPSDK.IPSDKIPLStats as stats
import PyIPSDK.IPSDKIPLUtility as util

Then we define the input parameters.

# retrieve program parameters
inputImgPath, outputImgPath, inHalfKnlSizeX, inHalfKnlSizeY, inOptNbClasses = readCmdArguments(argv)

And we load our input image from the associated TIFF file:

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)

Once all input parameters are initialized, we compute the local entropy image by calling the function ipsdk::imaproc::stats::localEntropy2dImg.

Note that this call is surrounded by a chronometer start and by the corresponding elapsed time retrieval.

# boundary 2d image computation
tStart = time.perf_counter()
outImg = stats.localEntropy2dImg(inImg, inHalfKnlSizeX, inHalfKnlSizeY, inOptNbClasses)
tEnd = time.perf_counter()
print("The application needed " + str(tEnd-tStart) + " seconds.")

The resulting output image is then saved to the TIFF file specified in object "outImgFilePath":

# save generated image
print("Writing result in file : " + outputImgPath)
PyIPSDK.saveTiffImageFile(outputImgPath, outImg)

See the full source listing