IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

module demonstrating the usage of a mean smoothing filter on a 3d image More...

module demonstrating the usage of a mean smoothing filter on a 3d image

Overview

This application applies a mean smoothing filter on a 3d input image loaded from a given input TIFF file, and saves the result in a given TIFF file.

See also
Mean smoothing 3d algorithm

Usage

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

   <application_script_filename> [--inputImg3dFilePath <input_3d_image_file_path>] [--outputImg3dFilePath <output_3d_image_file_path>] [--inHalfKnlSizeX <half_kernel_size_along_x>] [--inHalfKnlSizeY <half_kernel_size_along_y>] [--inHalfKnlSizeZ <half_kernel_size_along_z>]
     
   Arguments:
      --inputImg3dFilePath  optional; specifies the name of the TIFF file, from
                            which the 3d input image will be loaded; if not 
                            specified by the user, the input image is loaded from
                            file 
                            <DEV_ROOT>/data/Sample/images/Rope3d.tif
                          
      --outputImg3dFilePath optional; specifies the name of the TIFF file, in
                            which the 3d output image resulting from the 
                            computation of the mean smoothing filter will be saved;
                            if not specified by the user, the output image is 
                            saved in file
                            <TEMPORARY_IPSDK_DIR>/Sample/meanSmoothing3d.tif

      --inHalfKnlSizeX      optional; specifies the value of half kernel size along x axis,
                            used while applying the mean smoothing filter; if not
                            specified by the user, equals to 3 by default

      --inHalfKnlSizeY      optional; specifies the value of half kernel size along y axis,
                            used while applying the mean smoothing filter; if not
                            specified by the user, equals to 3 by default

      --inHalfKnlSizeZ      optional; specifies the value of half kernel size along z axis,
                            used while applying the mean smoothing filter; if not
                            specified by the user, equals to 3 by default

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

Source code documentation

We start by importing all necessary libraries:

import os
import sys, getopt
import PyIPSDK
import PyIPSDK.IPSDKIPLFiltering as filter

Then we define the input parameters.

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

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

# opening of 3D input image
# specifying argument PyIPSDK.eTiffDirectoryMode.eTDM_Volume, input image plans are interpreted as a 3d stack
inImg = PyIPSDK.loadTiffImageFile(inputImgPath, PyIPSDK.eTiffDirectoryMode.eTDM_Volume)

We then call the mean smoothing 3d calculation on the input image.

# mean smoothing computation
outImg = filter.meanSmoothing3dImg(inImg, inHalfKnlSizeX, inHalfKnlSizeY, inHalfKnlSizeZ);

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