[Insight-users] Progress event and DiscreteGaussianImageFilter

Didier Rajon didier at ufl.edu
Mon Sep 12 12:40:26 EDT 2005


Hi,
I'm using itkDiscreteGaussianImageFilter with an observer on the
progress event.
The progress value that I get each time the observer receives the event
has a strange behavior.  As the filter executes, the progress goes up to
about 10.7% , then drops to about 7.1%, then goes up again to about
10.7%, then drops again, etc.  The progress value keeps oscilating about
25 times during the execution.  The drop down is always the same (3.6%)
but the progress value seems to go up a little bit more after each
oscillation.  At the last oscillation, the maximum progress is 14.3%,
and then, the filter terminates.
I checked a little bit the code of the filter, and it seems that there
is something incoherent between the way the StreamingFilter works and
the way the ProgressAccumulator works.  The progress accumulator is
registered for only 4 sub-filters (3D smoothing in my case) and the
whole filtering process is divided into 28 stages (3D image dataset and
3D smoothing in my case).  This value of 28 coresponds to a stage
execution of 3.57% (1/28) per stage.  This value of 3.57% corresponds to
the size of my drop at each oscillation, besides that, 3 x 3.57 = 10.7
and  4 x 3.57 = 14.3, which are the values of my first and last maximum
progress.
Note that I just switched to ITK 2.2 and that the problem never happened
when I was using ITK 2.0.
I'm using ITK with Linux Redhat 9.0.
I attached a little program that reproduces the problem.

Thanks for considering this problem,

Didier.

-- 
Didier Rajon
Department of Neurological Surgery
University of Florida
MBI, L2100 PO Box 100265
Gainesville, FL, 32610-0265
Tel: (352) 294 0144
Fax: (352) 392 8413


-------------- next part --------------
// system include files
#include <iostream>
#include <sstream>
#include <string>

// itk include files
#include "itkImageFileReader.h"
#include "itkCastImageFilter.h"
#include "itkDiscreteGaussianImageFilter.h"

// That's to show the progress on the standard output.
void DisplayITKEventCallback(itk::Object *caller,
                             const itk::EventObject& event,
                             void *clientData)
  {
  itk::ProcessObject *processObject = (itk::ProcessObject*)caller;
  if (typeid(event) == typeid(itk::ProgressEvent)) {
    std::cout << "ITK Progress event received from "
              << processObject->GetNameOfClass() << ". Progress is "
              << 100.0 * processObject->GetProgress() << " %."
              << std::endl;
    }
  }

main (int argc, char **argv)
  {
  // 0) To get and check the program arguments.
  /////////////////////////////////////////////
  std::string inputFileName;
    {
    // To check the command line
    if ( argc != 2 ) {
      std::cerr << "Error: bad command-line. Try again with command-line:" << std::endl;
      std::cerr << "SmoothImage InputFileName" << std::endl;
      std::cerr << " - InputFileName: The full path name of the file that contains the input image." << std::endl;
      std::cerr << "ex: SmoothImage ./MyImageFile.vtk" << std::endl;
      exit(0);
      }
    // To get the arguments.
    inputFileName = argv[1];
    std::cout << std::endl << "Executing program SmoothImage." << std::endl;
    std::cout << "Input file name:   " << inputFileName << "." << std::endl;
    std::cout << std::endl;
    }

  // 1) To define the image type.
  ///////////////////////////////
  const unsigned int ImageDimension = 3;
  typedef unsigned short InputVoxelType;
  typedef itk::Image<InputVoxelType, ImageDimension> InputImageType;
  typedef float WorkingVoxelType;
  typedef itk::Image<WorkingVoxelType, ImageDimension> WorkingImageType;

  // 2) To read the input image.
  //////////////////////////////
  InputImageType::Pointer inputImage;
    {
    std::cout << "Reading input image." << std::endl;
    typedef itk::ImageFileReader<InputImageType> ReaderType;
    ReaderType::Pointer imageReader = ReaderType::New();

    // To set the filter attributes.
    imageReader->SetFileName(inputFileName.c_str());

    // To execute the filter.
    try {
      imageReader->Update();
      std::cout << "Execution terminated successfully." << std::endl;
      }
    catch(itk::ExceptionObject & err) {
      std::cerr << err << std::endl;
      exit(0);
      }

    inputImage = imageReader->GetOutput();
    }

  // 3) To cast the image into floats (because the filter requires a signed voxel type).
  //////////////////////////////////////////////////////////////////////////////////////
  WorkingImageType::Pointer castedImage;
    {
    std::cout << "Casting the image." << std::endl;
    typedef itk::CastImageFilter<InputImageType, WorkingImageType> FilterType;
    FilterType::Pointer imageCaster = FilterType::New();

    // To set an observer on the progress event.
    typedef itk::CStyleCommand         commandType;
    typedef commandType::Pointer       commandPointer;
    commandPointer printCallback = commandType::New();
    printCallback->SetCallback(DisplayITKEventCallback);
    imageCaster->AddObserver(itk::ProgressEvent(), printCallback);

    // To set the filter attributes.
    imageCaster->SetInput(inputImage);

    // To execute the filter.
    try {
      imageCaster->Update();
      std::cout << "Execution terminated successfully."
                << std::endl;
      }
    catch(itk::ExceptionObject & err) {
      std::cerr << err << std::endl;
      exit(0);
      }

    castedImage = imageCaster->GetOutput();
    }

  // 4) To smooth the image.
  //////////////////////////
  WorkingImageType::Pointer smoothedImage;
    {
    std::cout << "Smoothing the image." << std::endl;
    typedef itk::DiscreteGaussianImageFilter<WorkingImageType, WorkingImageType> FilterType;
    FilterType::Pointer imageSmoother = FilterType::New();

    // To set an observer on the progress event.
    typedef itk::CStyleCommand         commandType;
    typedef commandType::Pointer       commandPointer;
    commandPointer printCallback = commandType::New();
    printCallback->SetCallback(DisplayITKEventCallback);
    imageSmoother->AddObserver(itk::ProgressEvent(), printCallback);

    // To set the filter attributes.
    imageSmoother->SetInput(castedImage);
    imageSmoother->SetUseImageSpacingOff();
    imageSmoother->SetVariance(1.0);

    // To execute the filter.
    try {
      imageSmoother->Update();
      std::cout << "Execution terminated successfully."
                << std::endl;
      }
    catch(itk::ExceptionObject & err) {
      std::cerr << err << std::endl;
      exit(0);
      }

    smoothedImage = imageSmoother->GetOutput();
    }
  }





More information about the Insight-users mailing list