IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

module demonstrating the computation of local variance on a 2d image More...

module demonstrating the computation of local variance on a 2d image

Overview

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

See also
variance 2d algorithm

Usage

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

   <application_exe_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>]
     
   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 variance
                          computation will be saved; if not specified by the
                          user, the output image is saved in file
                          <TEMPORARY_IPSDK_DIR>/Sample/variance.tif
                          
      --inHalfKnlSizeX    optional; specifies the half size, along x axis, of
                          kernel used to compute the variance image; default
                          value equals to 1
                          
      --inHalfKnlSizeY    optional; specifies the half size, along y axis, of
                          kernel used to compute the variance image; default
                          value equals to 1

Here is a snapshot of default input image used by the application and of corresponding output image when application is launched without any argument:

Sample_Variance2d.png

Source code documentation

We start by importing all necessary libraries:

import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLStats as stats

Then we define the input parameters.

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

We load our input image from the associated Tiff file, by calling the function ipsdk::image::file::loadTiffImageFile.

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

We then call the 2d variance calculation on the input image.

# lightness computation
outImg = stats.variance2dImg(inImg, inHalfKnlSizeX, inHalfKnlSizeY);

Lastly, we save the image resulting from the operation to the Tiff file.

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

See the full source listing