Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::DemonsRegistration Class Reference

This class performes a demons registration between two images with the same modality.. More...

#include <mitkDemonsRegistration.h>

Inheritance diagram for mitk::DemonsRegistration:
Inheritance graph
[legend]
Collaboration diagram for mitk::DemonsRegistration:
Collaboration graph
[legend]

List of all members.

Public Types

typedef DemonsRegistration Self
typedef RegistrationBase Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
void SetNumberOfIterations (int iterations)
 Sets the number of iterations which will be performed during the registration process.
void SetStandardDeviation (float deviation)
 Sets the standard deviation used by the demons registration.
void SetSaveDeformationField (bool saveField)
 Sets whether the resulting deformation field should be saved or not.
void SetDeformationFieldFileName (const char *fieldName)
 Sets the filename for the resulting deformation field.
void SetSaveResult (bool saveResult)
 Sets whether the result should be saved or not.
void SetResultFileName (const char *resultName)
 Sets the filename for the resulting deformed image.
itk::Image< itk::Vector< float, 3 >
, 3 >::Pointer 
GetDeformationField ()
 Returns the deformation field, which results by the registration.
virtual void GenerateData ()
 Starts the demons registration.

Static Public Member Functions

static Pointer New ()
 Method for creation through the object factory.

Protected Member Functions

 DemonsRegistration ()
 Default constructor.
virtual ~DemonsRegistration ()
 Default destructor.
template<typename TPixel , unsigned int VImageDimension>
void GenerateData2 (itk::Image< TPixel, VImageDimension > *itkImage1)
 Template class to perform the demons registration with any kind of image. Called by GenerateData().

Protected Attributes

int m_Iterations
float m_StandardDeviation
const char * m_FieldName
const char * m_ResultName
bool m_SaveField
bool m_SaveResult
itk::Image< class itk::Vector
< float, 3 >, 3 >::Pointer 
m_DeformationField

Detailed Description

This class performes a demons registration between two images with the same modality..

Author:
Daniel Stein

Definition at line 38 of file mitkDemonsRegistration.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::DemonsRegistration::ConstPointer

Reimplemented from mitk::RegistrationBase.

Definition at line 43 of file mitkDemonsRegistration.h.

typedef itk::SmartPointer<Self> mitk::DemonsRegistration::Pointer

Reimplemented from mitk::RegistrationBase.

Definition at line 43 of file mitkDemonsRegistration.h.

Reimplemented from mitk::RegistrationBase.

Definition at line 43 of file mitkDemonsRegistration.h.

Reimplemented from mitk::RegistrationBase.

Definition at line 43 of file mitkDemonsRegistration.h.


Constructor & Destructor Documentation

mitk::DemonsRegistration::DemonsRegistration (  ) [protected]

Default constructor.

Definition at line 25 of file mitkDemonsRegistration.cpp.

                                        :
    m_Iterations(50),
    m_StandardDeviation(1.0),
    m_FieldName("newField.mhd"),
    m_ResultName("deformedImage.mhd"),
    m_SaveField(true),
    m_SaveResult(true),
    m_DeformationField(NULL)
  {

mitk::DemonsRegistration::~DemonsRegistration (  ) [protected, virtual]

Default destructor.

Definition at line 37 of file mitkDemonsRegistration.cpp.

  {

Member Function Documentation

virtual void mitk::DemonsRegistration::GenerateData (  ) [inline, virtual]

Starts the demons registration.

Reimplemented from mitk::ImageSource.

Definition at line 88 of file mitkDemonsRegistration.h.

References AccessByItk.

    {
      if (this->GetInput())
      {
        AccessByItk(this->GetInput(), GenerateData2);
      }
    }
template<typename TPixel , unsigned int VImageDimension>
void mitk::DemonsRegistration::GenerateData2 ( itk::Image< TPixel, VImageDimension > *  itkImage1 ) [protected]

Template class to perform the demons registration with any kind of image. Called by GenerateData().

Definition at line 77 of file mitkDemonsRegistration.cpp.

References mitk::RegistrationBase::AddStepsToDo(), mitk::CastToItkImage(), mitk::CastToMitkImage(), mitk::ImageSource::GetOutput(), m_DeformationField, m_FieldName, m_Iterations, mitk::RegistrationBase::m_ReferenceImage, m_ResultName, m_SaveField, m_SaveResult, m_StandardDeviation, MITK_ERROR, New(), mitk::RegistrationBase::SetProgress(), and mitk::RegistrationBase::SetRemainingProgress().

  {
    typedef typename itk::Image< TPixel, VImageDimension >  FixedImageType;
    typedef typename itk::Image< TPixel, VImageDimension >  MovingImageType;

    typedef float InternalPixelType;
    typedef typename itk::Image< InternalPixelType, VImageDimension > InternalImageType;
    typedef typename itk::CastImageFilter< FixedImageType, 
                                  InternalImageType > FixedImageCasterType;
    typedef typename itk::CastImageFilter< MovingImageType, 
                                  InternalImageType > MovingImageCasterType;
    typedef typename itk::Image< InternalPixelType, VImageDimension > InternalImageType;
    typedef typename itk::Vector< float, VImageDimension >    VectorPixelType;
    typedef typename itk::Image<  VectorPixelType, VImageDimension > DeformationFieldType;
    typedef typename itk::DemonsRegistrationFilter<
                                  InternalImageType,
                                  InternalImageType,
                                  DeformationFieldType>   RegistrationFilterType;
    typedef typename itk::WarpImageFilter<
                            MovingImageType, 
                            MovingImageType,
                            DeformationFieldType  >     WarperType;
    typedef typename itk::LinearInterpolateImageFunction<
                                    MovingImageType,
                                    double          >  InterpolatorType;

    typedef  TPixel  OutputPixelType;
    typedef typename itk::Image< OutputPixelType, VImageDimension > OutputImageType;
    typedef typename itk::CastImageFilter< 
                          MovingImageType,
                          OutputImageType > CastFilterType;
    typedef typename itk::ImageFileWriter< OutputImageType >  WriterType;
    typedef typename itk::ImageFileWriter< DeformationFieldType >  FieldWriterType;

    typename FixedImageType::Pointer fixedImage = FixedImageType::New();
    mitk::CastToItkImage(m_ReferenceImage, fixedImage);
    typename MovingImageType::Pointer movingImage = itkImage1;

    if (fixedImage.IsNotNull() && movingImage.IsNotNull())
    {
      typename RegistrationFilterType::Pointer filter = RegistrationFilterType::New();

      this->AddStepsToDo(4);
      typename itk::ReceptorMemberCommand<DemonsRegistration>::Pointer command = itk::ReceptorMemberCommand<DemonsRegistration>::New();
      command->SetCallbackFunction(this, &DemonsRegistration::SetProgress);
      filter->AddObserver( itk::IterationEvent(), command );

      typename FixedImageCasterType::Pointer fixedImageCaster = FixedImageCasterType::New();
      fixedImageCaster->SetInput(fixedImage);
      filter->SetFixedImage( fixedImageCaster->GetOutput() );
      typename MovingImageCasterType::Pointer movingImageCaster = MovingImageCasterType::New();
      movingImageCaster->SetInput(movingImage);
      filter->SetMovingImage(movingImageCaster->GetOutput());
      filter->SetNumberOfIterations( m_Iterations );
      filter->SetStandardDeviations( m_StandardDeviation );
      filter->Update();

      typename WarperType::Pointer warper = WarperType::New();
      typename InterpolatorType::Pointer interpolator = InterpolatorType::New();

      warper->SetInput( movingImage );
      warper->SetInterpolator( interpolator );
      warper->SetOutputSpacing( fixedImage->GetSpacing() );
      warper->SetOutputOrigin( fixedImage->GetOrigin() );
      warper->SetOutputDirection( fixedImage->GetDirection());
      warper->SetDeformationField( filter->GetOutput() );
      warper->Update();
      Image::Pointer outputImage = this->GetOutput();
      mitk::CastToMitkImage( warper->GetOutput(), outputImage );


      typename WriterType::Pointer      writer =  WriterType::New();
      typename CastFilterType::Pointer  caster =  CastFilterType::New(); 

      writer->SetFileName( m_ResultName );
  
      caster->SetInput( warper->GetOutput() );
      writer->SetInput( caster->GetOutput()   );
      if(m_SaveResult)
      {
        writer->Update();
      }

      if (VImageDimension == 2)
      {
        typedef DeformationFieldType  VectorImage2DType;
        typedef typename DeformationFieldType::PixelType Vector2DType;

        typename VectorImage2DType::ConstPointer vectorImage2D = filter->GetOutput();

        typename VectorImage2DType::RegionType  region2D = vectorImage2D->GetBufferedRegion();
        typename VectorImage2DType::IndexType   index2D  = region2D.GetIndex();
        typename VectorImage2DType::SizeType    size2D   = region2D.GetSize(); 


        typedef typename itk::Vector< float,       3 >  Vector3DType;
        typedef typename itk::Image< Vector3DType, 3 >  VectorImage3DType;

        typedef typename itk::ImageFileWriter< VectorImage3DType > WriterType;

        typename WriterType::Pointer writer3D = WriterType::New();

        typename VectorImage3DType::Pointer vectorImage3D = VectorImage3DType::New();
        
        typename VectorImage3DType::RegionType  region3D;
        typename VectorImage3DType::IndexType   index3D;
        typename VectorImage3DType::SizeType    size3D;

        index3D[0] = index2D[0];
        index3D[1] = index2D[1];
        index3D[2] = 0;
        
        size3D[0]  = size2D[0];
        size3D[1]  = size2D[1];
        size3D[2]  = 1;

        region3D.SetSize( size3D );
        region3D.SetIndex( index3D );

        typename VectorImage2DType::SpacingType spacing2D   = vectorImage2D->GetSpacing();
        typename VectorImage3DType::SpacingType spacing3D;

        spacing3D[0] = spacing2D[0];
        spacing3D[1] = spacing2D[1];
        spacing3D[2] = 1.0;

        vectorImage3D->SetSpacing( spacing3D );

        vectorImage3D->SetRegions( region3D );
        vectorImage3D->Allocate();
        
        typedef typename itk::ImageRegionConstIterator< VectorImage2DType > Iterator2DType;

        typedef typename itk::ImageRegionIterator< VectorImage3DType > Iterator3DType;

        Iterator2DType  it2( vectorImage2D, region2D );
        Iterator3DType  it3( vectorImage3D, region3D );

        it2.GoToBegin();
        it3.GoToBegin();

        Vector2DType vector2D;
        Vector3DType vector3D;

        vector3D[2] = 0; // set Z component to zero.

        while( !it2.IsAtEnd() )
        {
          vector2D = it2.Get();
          vector3D[0] = vector2D[0];  
          vector3D[1] = vector2D[1];  
          it3.Set( vector3D );
          ++it2;
          ++it3;
        }

        writer3D->SetInput( vectorImage3D );
        m_DeformationField = vectorImage3D;

        writer3D->SetFileName( m_FieldName );

        try
        {
          if(m_SaveField)
          {
            writer3D->Update();
          }
        }
        catch( itk::ExceptionObject & excp )
        {
          MITK_ERROR << excp << std::endl;
        }
      }
      else
      {
        typename FieldWriterType::Pointer      fieldwriter =  FieldWriterType::New();
        fieldwriter->SetFileName(m_FieldName);
        fieldwriter->SetInput( filter->GetOutput() );
        m_DeformationField = (itk::Image<itk::Vector<float, 3>,3> *)(filter->GetOutput());
        if(m_SaveField)
        {
          fieldwriter->Update();
        }
      }
      this->SetRemainingProgress(4);
    }
virtual const char* mitk::DemonsRegistration::GetClassName (  ) const [virtual]

Reimplemented from mitk::RegistrationBase.

itk::Image< itk::Vector< float, 3 >, 3 >::Pointer mitk::DemonsRegistration::GetDeformationField (  )

Returns the deformation field, which results by the registration.

Definition at line 71 of file mitkDemonsRegistration.cpp.

References m_DeformationField.

  {
    return m_DeformationField;
static Pointer mitk::DemonsRegistration::New (  ) [static]

Method for creation through the object factory.

Reimplemented from mitk::RegistrationBase.

Referenced by QmitkDemonsRegistrationView::CalculateTransformation(), GenerateData2(), and mitkDemonsRegistrationTest().

void mitk::DemonsRegistration::SetDeformationFieldFileName ( const char *  fieldName )

Sets the filename for the resulting deformation field.

Definition at line 56 of file mitkDemonsRegistration.cpp.

References m_FieldName.

  {
    m_FieldName = fieldName;
void mitk::DemonsRegistration::SetNumberOfIterations ( int  iterations )

Sets the number of iterations which will be performed during the registration process.

Definition at line 41 of file mitkDemonsRegistration.cpp.

References m_Iterations.

  {
    m_Iterations = iterations;
void mitk::DemonsRegistration::SetResultFileName ( const char *  resultName )

Sets the filename for the resulting deformed image.

Definition at line 66 of file mitkDemonsRegistration.cpp.

References m_ResultName.

  {
    m_ResultName = resultName;
void mitk::DemonsRegistration::SetSaveDeformationField ( bool  saveField )

Sets whether the resulting deformation field should be saved or not.

Definition at line 51 of file mitkDemonsRegistration.cpp.

References m_SaveField.

  {
    m_SaveField = saveField;
void mitk::DemonsRegistration::SetSaveResult ( bool  saveResult )

Sets whether the result should be saved or not.

Definition at line 61 of file mitkDemonsRegistration.cpp.

References m_SaveResult.

  {
    m_SaveResult = saveResult;
void mitk::DemonsRegistration::SetStandardDeviation ( float  deviation )

Sets the standard deviation used by the demons registration.

Definition at line 46 of file mitkDemonsRegistration.cpp.

References m_StandardDeviation.

  {
    m_StandardDeviation = deviation;

Member Data Documentation

itk::Image<class itk::Vector<float, 3>,3>::Pointer mitk::DemonsRegistration::m_DeformationField [protected]

Definition at line 121 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and GetDeformationField().

const char* mitk::DemonsRegistration::m_FieldName [protected]

Definition at line 117 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetDeformationFieldFileName().

Definition at line 115 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetNumberOfIterations().

const char* mitk::DemonsRegistration::m_ResultName [protected]

Definition at line 118 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetResultFileName().

Definition at line 119 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetSaveDeformationField().

Definition at line 120 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetSaveResult().

Definition at line 116 of file mitkDemonsRegistration.h.

Referenced by GenerateData2(), and SetStandardDeviation().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines