IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

module demonstrating the computation of boundary on a 2d binary image More...

module demonstrating the computation of boundary on a 2d binary image

Overview

This script computes the boundary image on a 2d binary input image loaded from a given input Raw file, and saves the result in a given Raw file.

See also
boundary 2d morphological algorithm

Usage

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

   <application_script_filename> [--inputImgFilePath <input_image_file_path> --imgXSz <image_x_size> --imgYSz <image_y_size>] [--outputImgFilePath <output_image_file_path>]

     
   Arguments:
      --inputImgFilePath  optional; specifies the name of the RAW 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/MorphoBin2d1.raw
                          
      --outputImgFilePath optional; specifies the name of the RAW 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/boundary.raw

      --imgXSz            mandatory if inputImgFilePath option is specified,
                          ignored otherwise; specifies the width of input image

      --imgYSz            mandatory if inputImgFilePath option is specified,
                          ignored otherwise; specifies the height of input image

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_Boundary2d.png

Source code documentation

We start by importing all necessary libraries:

import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho

Then we define the input parameters.

# retrieve program parameters
inputImgPath, outputImgPath, sizeX, sizeY = readCmdArguments(argv)

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

# opening of input image
imgGeometry = PyIPSDK.geometry2d(PyIPSDK.eImageBufferType.eIBT_Binary, sizeX, sizeY)
inImg = PyIPSDK.loadRawImageFile(inputImgPath, imgGeometry)

We then apply the boundary image processing algorithm on the input image.

# boundary 2d image computation
outImg = morpho.boundary2dImg(inImg)

Lastly, we save the image resulting from the "boundary" operation to the Raw file.

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

See the full source listing