IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

module demonstrating shape filtering on 2d images More...

module demonstrating shape filtering on 2d images

Overview

This application proceeds to a shape filtering operation from an input image TIFF files cupple (a binary or label image and an optional grey level image) and a filtering formula.

See also
Shape Filtering 2d algorithm

Usage

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

   <application_script_filename> [--inputGreyImgPath <input_grey_image_file_path>] [--inputBinLabImgPath <input_binary_image_file_path>] [--inputFilterFormula <input_filter_formula>] [--outputImgFilePath <output_image_file_path>]
     
   Arguments:
      --inputGreyImgPath      optional; specifies the name of the TIFF file, from
                              which the input grey level image will be loaded; if not 
                              specified by the user, used input image is loaded from
                              file 
                              <DEV_ROOT>/data/Sample/images/blobs_483x348_UInt8.tif
                          
      --inputBinLabImgPath    optional; specifies the name of the TIFF file, from
                              which the input binary or label image will be loaded; 
                              if not specified by the user, the input image is
                              loaded from file 
                              <DEV_ROOT>/data/Sample/images/blobs_483x348_Binary.tif

       --inputFilterFormula   optional; specifies the formula string used to filter
                              shapes from input binary/label image.
                              if not specified by the user, the input filter formula
                              will be set to
                              Area2dMsr > 800

       --outputImgFilePath    optional; specifies the name of the TIFF file, in
                              which the output filtered image will be saved; if not 
                              specified by the user, the output image file is saved
                              to file
                              <TEMPORARY_IPSDK_DIR>/Sample/shapeFiltering2dImg.tif

Here is a snapshot of default input images used by the application and of corresponding output results with the following filtering criteria Circularity<0.9 and Mean<170:

Sample_ShapeFiltering2dImg.png

Central displayed table correspond to the working data used during filtering operation.

Source code documentation

We start by importing all necessary libraries:

import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis

Then we define the input parameters.

# retrieve program parameters
inputImgPath, outputImgPath, inputBinImgPath, inputFilterFormula = readCmdArguments(argv)

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

# opening of input image
inGreyImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inBinImg = PyIPSDK.loadTiffImageFile(inputBinImgPath)

We then apply the main shape filtering algorithm on input image using input formula string.

# shape 2d filtering operation
outImg = shapeanalysis.shapeFiltering2dImg(inBinImg, inGreyImg, inputFilterFormula)

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