Personal tools
You are here: Home / cmgui / Wiki / Validate cmgui itk filters
Log in

Forgot your password?

Validate cmgui itk filters


All itk filters have code that tests them to ensure that they are working as expected. These tests can be run after editing itk source to see if the filters still performs as expected.

We should also test the itk filters used by cmgui in the same way to verify that they work and produce the expected output.

When an itk image filter has been added in to cmgui it should ideally be validated before being added to the repository. Code should also be added to a regularly run test example that checks the output.

A good test would be to run the filter on the same input image that the itk test uses and then compare the output image with the base line output image that itk uses. An image diff would be required to ensure the two images are the same (within a specified tolerance). To be able to use this stratey we need a reasonable understanding of how filters are tested under itk so we can find the appropriate image files and parameters to use for our cmgui tests.

Itk filter testing

A list of tests for itk filters can be found in /itk/src/Examples/Filtering/CMakeLists.txt

This file adds an executable and a test for each filter. For example it adds an exectuble for the GradientMagnitudeRecursiveGaussianImageFilter

ADD_EXECUTABLE(GradientMagnitudeRecursiveGaussianImageFilter GradientMagnitudeRecursiveGaussianImageFilter.cxx )
TARGET_LINK_LIBRARIES(GradientMagnitudeRecursiveGaussianImageFilter ITKCommon ITKIO)

The code to add the actual test is located later in the file and details the executable file, the input image, the output image any command line parameters to run the test with. The code to add the test for the example above looks as follows

ADD_TEST( GradientMagnitudeRecursiveGaussianImageFilterTest ${FILTERING_EXAMPLES8}
  --compare ${BASELINE}/GradientMagnitudeRecursiveGaussianImageFilter.png

Notice it first details the location of the baseline comparison image and test output image so that they can be compared. Following that is the rest of the information required to run the actual test.

You can determine what variables the command line arguments match up to be opening the source file for the executable ('GradientMagnitudeRecursiveGaussianImageFilter.cxx') and searching on 'argv' to see which values are set. For the above case

  • argv0 is the executable, GradientMagnitudeRecursiveGaussianImageFilterTest
  • argv1 is the input image filename, ${ITK_SOURCE_DIR}/Examples/Data/BrainProtonDensitySlice.png
  • argv2 is the output image file name, ${TEMP}/GradientMagnitudeRecursiveGaussianImageFilter.png
  • argv3 is the value for the parameter sigma, 5

The baseline images are a good resource for seeing what a filter is expected to do for a particular input image.

For the above test we could open up the input image and the baseline image in gimp to see what effect the GradientMagnitudeRecursiveGaussianImageFilter has.

The source image will be located somewhere like 'itk/src/Examples/Data/BrainProtonDensitySlice.png' The baseline image will be somewhere like 'itk/src/Testing/Data/Baseline/Filtering/GradientAnisotropicDiffusionImageFilter.png'

Cmgui filter tests (for itk image based filters)

  • Determine the input image and baseline image for the corresponding itk test.
  • Determine the filter parameters used in the itk test.
  • Write a comfile to read the input image into a texture, create a sample field, filter the field and than write out the resulting image.
  • Compare the output image from cmgui against the base line image. See Comparing two images for ideas on how to do this.

Issues to be aware of when comparing Cmgui and itk tests

  • In the ITK test examples the itkImageReader takes care of reading an image and converting it to the required image output type. Most filters work on a single component (grayscale) image so colour images are converted to grayscale by the image reader. If reading colour images with cmgui, an extra field needs to be created to deal with the required conversion. The input image field created from the image will need to be converted to a grayscale input field by defining a sum_component field, using the same weightings itk uses to create grayscale images

    luminance = (2125 R + 7154 G + 0721 B)/10000
  • In general luminance in itk is treated as a value between 0 and 255 whereas cmgui uses values between 0 and 1. This means when setting any luminance based parameters, the itk test parameter values need to be divided by 255.

  • An alternative to dividing by 255 is to scale the input image by 255 and use the values from the itk tests. This makes setting up equivalent test much simpler but requires scaling the output image by 1/255.

  • Cmgui and itk tests based on the same parameters and images seem to give results which are close but not identical, possibly due to rounding error?