Insight Toolkit is a cross-platform, open-source application development framework widely used for the development of image segmentation and image registration programs, especially in the medical domain. This work aims to explore some of the basic operations that are possible with this package while discussing the mathematical concepts behind them.
The sections explored in this repository are,
- Smoothing operations
- Registration operations
- Filter Writing method
- Module Writing method
The file structure of this repository is as follows:
.
├── assets # images used for the operations
├── exports # images exported by the operations
├── figures # figures used for the presentation purpose
├── itk-explore.ipynb # the main notebook for the exploration
├── presentation-figures.ipynb # notebook to create presentation figures
├── ReadMe.md
└── src # the directory holding the main source codes
The Google Slides version of the presentation slides can be found here. The PDF version of the presentation slides can be found here.
ITK provides a number of smoothing operations to remove noise from images for the enhancement of visibility. These operations are mentioned under Book 2, Section 2.7 in the ITK Software Guide.
These operations are primarily done by convolving a given image with a kernel, which applies a weighted average to each pixel and its neighboring pixels, resulting in a softened and blurred effect.
The smoothing operations provided by ITK can be divided into two main groups.
- Primitive Smoothing
- Edge Preserving Smoothing
Out of the many primitive smoothing operations provided by ITK, the following operations were analyzed;
- Discrete gaussian blurring
- Binomial blurring
- Median blurring
- IIR blurring
Discrete Gaussian blurring is widely regarded as one of the most fundamental and commonly employed techniques for image blurring. This method is favored for its exceptional characteristics. Read more at Wikipedia. The used kernel can be mathematically modeled by the equation below;
Binomial blurring is usually an iterative process. At a higher number of iterations, the operation becomes closer to the Gaussian operation. The kernel has the coefficients of the binomial expansion (
Median blurring is suitable when the input image has impulsive noise (e.g., salt and pepper noise). This operation selects the median value under the kernel in the input image and returns that to the output image. Read more at Wikipedia.
An example of a median in filter operation Original image Kernel applied image
Out of the many edge-preserving smoothing operations provided by ITK, the following operations were analyzed.
- Gradient anisotropic diffusion
- Curvature anisotropic diffusion
The basic idea behind edge-preserving smoothing is to somehow apply the blurring operation only to regions without edges.
This method calculates the gradient of the given image and uses it as the mask for the blurring operation. This is an iterative process. This method was initially proposed by Perona and Malik in 1990. Read more in the original paper. The key mathematical formulation can be presented as;
Registration is the process of overlapping visual entities (images or 3D volumes) on top of each other for the purpose of processing or analysis. The implementation in ITK is documented under Book 2, Section 3 of the ITK Software Guide.
A typical registration framework will look like the following
Here there are two images; a Moving Image and a Fixed Image.
- The Transformer applies a transformation to the moving image.
- The Interpolator interpolates the transformed moving image at the pixel locations of the fixed image.
- The Metric compares the similarity between the fixed image and the moving image.
- The Optimizer iteratively adjusts the parameters of the Transform to minimize the distance resulting from the Metric.
In this scenario, the user is forced to do the interpolation in the domain of the Fixed Image. This might impose unwanted restraints in certain scenarios. Therefore, the ITKv4 registration framework provides an additional option to apply a transformation to the fixed image too. This transformation will remain the same throughout the iterative process.
Filter objects map operations throughout a given image. ITK provides a number of filters out of the box. To make the usage more flexible, the ITK Software Guide provides further instructions to write custom filters as per requirement. This is documented in Book 1, Section 8 of the ITK Software Guide.
ITK Filters are built with a “Pipeline” architecture through which data is streamed. The data starts at Sources (e.g., ImageReader…) and ends at Mappers (e.g., ImageWriter, Display,...). A pipeline is an interconnection of ProcessObjects and DataObjects. In the code implementations, they are instantiated with the definition of input and output types.
- Filter Selection and Execution: Determining the filters that need to be executed to minimize redundancy and reduce overall execution time.
- Initialization and Memory Allocation: Preparing filter output data objects and managing memory allocation for efficient data processing.
- Data Processing Determination: Assessing the amount of data processing required, accounting for memory constraints, and addressing kernel-size effects.
- Data Subdivision for Multi-Threading: Dividing data into subpieces to facilitate multi-threading and enhance performance.
- Dynamic Data Management: Managing the release of output data and utilizing filter caches for optimized downstream processing.
The execution of a filter operation is initialized by the DataObject::Update()
method at the required DataObject. This internally invokes,
DataObject::UpdateOutputInformation()
DataObject::PropagateRequestedRegion()
DataObject::UpdateOutputData()
- Information is metadata of the DataObject (origin, spacing, and LargestPossibleRegion…)
- Updates the information in data objects
- Also verifies parameters are valid and consistent
- Invokes
ProcessObject::GenerateOutputInformation()
- Configuring the filter’s input and output process objects to the correct size (setting BufferRegion)
- Invokes
DataObject::PropagateRequestedRegion
()` which can be overloaded
- Compares modified time, pipeline time, release data flag, and valid requested region
- If regeneration is required, delegate the task to
ProcessObject::UpdateOutputData()
- Internally invokes
GenerateData()
that can be overloaded
- Internally invokes
There are two methods to create a filter. Depending on the fine grab of the underlying functionalities, the user may select one of the following
- Creating a composite filter
- Extending a base class
Connect the inputs and outputs of multiple filters appropriately.
There are two major steps in this process
-
The extended class must expose public types for the class itself (Self) and its Superclass, and const and non-const smart pointers. For example:
using Self = CompositeExampleImageFilter; using Superclass = ImageToImageFilter<TImage, TImage>; using Pointer = SmartPointer<Self>; using ConstPointer = SmartPointer<const Self>;
ITK provides many base classes:
- ImageToImageFilter
- UnaryFunctorImageFilter
- BinaryFunctorImageFilter
- ImageFunction
- MeshToMeshFilter
- LightObject
-
Override the required methods.
Due to the larger community of developers, the community itself has come up with a basic architecture to Modularize source codes to organize functionalities in a modular architecture. ITK uses CMake to build the source codes. All the steps are documented in detail in Book 1, Section 9 of the ITK Software Guide.
This repository contains the code base of the ITK assignment under the University of Moratuwa, In19-S7-BM4301 Medical Image Processing module. The primary task of this assignment was to explore the Insight Toolkit which is a commonly used software in the field of medical image processing. The students were expected to refer to the ITK Software Guide and present the mathematics and usage behind its functionalities.