Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Support of VectorImage as template parameters for WarpImageFilter #8

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/Filtering/ImageGrid/include/itkWarpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class WarpImageFilter:
itkConceptMacro( SameDimensionCheck2,
( Concept::SameDimension< ImageDimension, DisplacementFieldDimension > ) );
itkConceptMacro( InputHasNumericTraitsCheck,
( Concept::HasNumericTraits< typename TInputImage::PixelType > ) );
( Concept::HasNumericTraits< typename TInputImage::InternalPixelType > ) );
itkConceptMacro( DisplacementFieldHasNumericTraitsCheck,
( Concept::HasNumericTraits< typename TDisplacementField::PixelType::ValueType > ) );
// End concept checking
Expand Down
14 changes: 12 additions & 2 deletions Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ WarpImageFilter< TInputImage, TOutputImage, TDisplacementField >
m_OutputOrigin.Fill(0.0);
m_OutputDirection.SetIdentity();
m_OutputSize.Fill(0);
m_EdgePaddingValue = NumericTraits< PixelType >::ZeroValue();
m_EdgePaddingValue = NumericTraits< typename OutputImageType::InternalPixelType >::ZeroValue();
m_OutputStartIndex.Fill(0);
// Setup default interpolator
typename DefaultInterpolatorType::Pointer interp =
Expand Down Expand Up @@ -179,6 +179,16 @@ WarpImageFilter< TInputImage, TOutputImage, TDisplacementField >
}
DisplacementFieldPointer fieldPtr = this->GetDisplacementField();


if (NumericTraits<PixelType>::GetLength(m_EdgePaddingValue)
!= this->GetInput()->GetNumberOfComponentsPerPixel() )
{
// Assume EdgePaddingValue has not been set externally
// initialize it here with ZeroValue, when we know the number of components
const PixelType& pixel = this->GetInput()->GetPixel( this->GetInput()->GetBufferedRegion().GetIndex() );
m_EdgePaddingValue = NumericTraits<PixelType>::ZeroValue( pixel );
}

// Connect input image to interpolator
m_Interpolator->SetInputImage( this->GetInput() );

Expand Down Expand Up @@ -292,7 +302,7 @@ WarpImageFilter< TInputImage, TOutputImage, TDisplacementField >
{
const DisplacementType input =
fieldPtr->GetPixel(neighIndex);
for ( unsigned int k = 0; k < ImageDimension; k++ )
for ( unsigned int k = 0; k < NumericTraits<DisplacementType>::GetLength(input); k++ )
{
output[k] += overlap * static_cast< double >( input[k] );
}
Expand Down
11 changes: 9 additions & 2 deletions Modules/Filtering/ImageGrid/test/itkWarpImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "itkWarpImageFilter.h"
#include "itkVectorCastImageFilter.h"
#include "itkStreamingImageFilter.h"
#include "itkVectorImage.h"
#include "itkMath.h"

// class to produce a linear image pattern
Expand Down Expand Up @@ -97,8 +98,8 @@ int itkWarpImageFilterTest(int, char* [] )
typedef float PixelType;
enum { ImageDimension = 2 };
typedef itk::Image<PixelType,ImageDimension> ImageType;

typedef itk::Vector<float,ImageDimension> VectorType;
typedef itk::VectorImage<PixelType,ImageDimension> VectorImageType;
typedef itk::Vector<float,ImageDimension> VectorType;
typedef itk::Image<VectorType,ImageDimension> FieldType;

bool testPassed = true;
Expand Down Expand Up @@ -169,7 +170,13 @@ int itkWarpImageFilterTest(int, char* [] )
}

//=============================================================
std::cout << "Instanciate WarpImageFilter with VectorImage.";
std::cout << std::endl;

typedef itk::WarpImageFilter<VectorImageType,VectorImageType,VectorImageType> WarpVectorImageFilterType;
WarpVectorImageFilterType::Pointer warpVectorImageFilter = WarpVectorImageFilterType::New();

//=============================================================
std::cout << "Run WarpImageFilter in standalone mode with progress.";
std::cout << std::endl;
typedef itk::WarpImageFilter<ImageType,ImageType,FieldType> WarperType;
Expand Down