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

WIP: streaming for resample image filter in case of linear transforms #82

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
3 changes: 2 additions & 1 deletion Modules/Core/Common/include/itkImageAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ struct ImageAlgorithm
* the physical space covered by the input
* region of the input image
*/
template<typename InputImageType, typename OutputImageType>
template<typename InputImageType, typename OutputImageType, typename TransformType>
static typename OutputImageType::RegionType
EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
const TransformType* transformPtr,
const InputImageType* inputImage,
const OutputImageType* outputImage);

Expand Down
12 changes: 10 additions & 2 deletions Modules/Core/Common/include/itkImageAlgorithm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ void ImageAlgorithm::DispatchedCopy( const InputImageType *inImage,
}
}

template<typename InputImageType, typename OutputImageType>
template<typename InputImageType, typename OutputImageType, typename TransformType>
typename OutputImageType::RegionType
ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType & inputRegion,
const TransformType* transformPtr,
const InputImageType* inputImage,
const OutputImageType* outputImage)
{
Expand Down Expand Up @@ -217,7 +218,14 @@ ImageAlgorithm::EnlargeRegionOverBox(const typename InputImageType::RegionType &

typedef Point< SpacePrecisionType, OutputImageType::ImageDimension > PointType;
PointType point;
inputImage->TransformContinuousIndexToPhysicalPoint(currentCornerIndex, point);
if ( transformPtr == ITK_NULLPTR)
{
inputImage->TransformContinuousIndexToPhysicalPoint(currentCornerIndex, point);
}
else
{
point = transformPtr->TransformPoint(currentCornerIndex);
}
outputImage->TransformPhysicalPointToContinuousIndex(point, corners[count]);
}

Expand Down
4 changes: 4 additions & 0 deletions Modules/Core/Common/test/itkImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "itkImage.h"
#include "itkFixedArray.h"
#include "itkImageAlgorithm.h"
#include "itkTransform.h"

int itkImageTest(int, char* [] )
{
Expand Down Expand Up @@ -121,7 +122,10 @@ int itkImageTest(int, char* [] )
regionRef.SetSize(sizeRef);
imageRef->SetRegions(regionRef);

typedef itk::Transform< double, Image::ImageDimension, Image::ImageDimension > TransformType;

Image::RegionType boxRegion = itk::ImageAlgorithm::EnlargeRegionOverBox(image->GetLargestPossibleRegion(),
static_cast< TransformType *>(ITK_NULLPTR),
image.GetPointer(),
imageRef.GetPointer());
Image::IndexType correctIndex; correctIndex.Fill(0);
Expand Down
36 changes: 33 additions & 3 deletions Modules/Filtering/ImageGrid/include/itkResampleImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "itkImageScanlineIterator.h"
#include "itkSpecialCoordinatesImage.h"
#include "itkDefaultConvertPixelTraits.h"
#include "itkImageAlgorithm.h"

namespace itk
{
Expand Down Expand Up @@ -492,10 +493,39 @@ ResampleImageFilter< TInputImage, TOutputImage, TInterpolatorPrecisionType, TTra
}

// Get pointers to the input and output
InputImagePointer inputPtr =
const_cast< TInputImage * >( this->GetInput() );
InputImageType * inputPtr =
const_cast< InputImageType * >( this->GetInput() );

// Determining the actual input region is non-trivial, especially

// Check whether the input or the output is a
// SpecialCoordinatesImage. If either are, then we cannot use the
// fast path since index mapping will definitely not be linear.
typedef SpecialCoordinatesImage< PixelType, ImageDimension > OutputSpecialCoordinatesImageType;
typedef SpecialCoordinatesImage< InputPixelType, InputImageDimension > InputSpecialCoordinatesImageType;

const bool isSpecialCoordinatesImage = ( dynamic_cast< const InputSpecialCoordinatesImageType * >( this->GetInput() )
|| dynamic_cast< const OutputSpecialCoordinatesImageType * >( this->GetOutput() ) );

const OutputImageType *outputPtr = this->GetOutput();
// Get the input transform
const TransformType *transformPtr = this->GetTransform();

// Check whether we can use upstream streaming for resampling. Upstream streaming
// can be used if the transformation is linear. Transform respond
// to the IsLinear() call.
if ( !isSpecialCoordinatesImage && transformPtr->GetTransformCategory() == TransformType::Linear )
{
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = ImageAlgorithm::EnlargeRegionOverBox(outputPtr->GetRequestedRegion(),
transformPtr,
outputPtr,
inputPtr);

inputPtr->SetRequestedRegion( inputRequestedRegion );
return;
}

// Otherwise, determining the actual input region is non-trivial, especially
// when we cannot assume anything about the transform being used.
// So we do the easy thing and request the entire input image.
//
Expand Down
4 changes: 4 additions & 0 deletions Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "itkProgressReporter.h"
#include "itkContinuousIndex.h"
#include "itkMath.h"
#include "itkTransform.h"

namespace itk
{
/**
Expand Down Expand Up @@ -438,8 +440,10 @@ WarpImageFilter< TInputImage, TOutputImage, TDisplacementField >
else
{
typedef typename TDisplacementField::RegionType DisplacementRegionType;
typedef itk::Transform< SpacePrecisionType, OutputImageType::ImageDimension, OutputImageType::ImageDimension > TransformType;

DisplacementRegionType fieldRequestedRegion = ImageAlgorithm::EnlargeRegionOverBox(outputPtr->GetRequestedRegion(),
static_cast< TransformType *>(ITK_NULLPTR),
outputPtr,
fieldPtr);
fieldPtr->SetRequestedRegion( fieldRequestedRegion );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6dcda44ce36e39fb6a792e26c8cd93830bab8edbe9f33385dc59b24bd6b40c99bbadf9b6ada967b1d1b6624e986f1161960d86db63b2d6b71da58eec0a2b911c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bbc1a32a82e88334df11c79f54ba4260ea291f8316c882d6360e7546739eb92109a169cc07abe32250a4e12e49a4bb8bad22c45580ccb78c4ee482fa68675e4f
20 changes: 20 additions & 0 deletions Modules/Filtering/ImageGrid/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ itkWrapPadImageTest.cxx
itkMirrorPadImageTest.cxx
itkResampleImageTest.cxx
itkResampleImageTest2.cxx
itkResampleImageTest2s.cxx
itkResampleImageTest3.cxx
itkResampleImageTest4.cxx
itkResampleImageTest5.cxx
itkResampleImageTest6.cxx
itkResampleImageTest7.cxx
itkResamplePhasedArray3DSpecialCoordinatesImageTest.cxx
itkPushPopTileImageFilterTest.cxx
itkShrinkImageStreamingTest.cxx
Expand Down Expand Up @@ -223,6 +225,22 @@ itk_add_test(NAME itkResampleImageTest2
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2b.png
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2c.png
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2d.png)
itk_add_test(NAME itkResampleImageTest2s
COMMAND ITKImageGridTestDriver
--compare DATA{Baseline/ResampleImageTest2.mha}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2a.mha
--compare DATA{Baseline/ResampleImageTest2.mha}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2b.mha
--compare DATA{Baseline/ResampleImageTest2NearestExtrapolate.mha}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2c.mha
--compare DATA{Baseline/ResampleImageTest2NearestExtrapolate.mha}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2d.mha
itkResampleImageTest2s DATA{${ITK_DATA_ROOT}/Input/cthead1.png}
DATA{${ITK_DATA_ROOT}/Input/circle.png}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2a.mha
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2b.mha
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2c.mha
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest2d.mha)
itk_add_test(NAME itkResampleImageTest3
COMMAND ITKImageGridTestDriver
--compare DATA{Baseline/ResampleImageTest3.png}
Expand All @@ -241,6 +259,8 @@ itk_add_test(NAME itkResampleImageTest6
--compare DATA{Baseline/ResampleImageTest6.png}
${ITK_TEST_OUTPUT_DIR}/ResampleImageTest6.png
itkResampleImageTest6 10 ${ITK_TEST_OUTPUT_DIR}/ResampleImageTest6.png)
itk_add_test(NAME itkResampleImageTest7
COMMAND ITKImageGridTestDriver itkResampleImageTest7)
itk_add_test(NAME itkResamplePhasedArray3DSpecialCoordinatesImageTest
COMMAND ITKImageGridTestDriver itkResamplePhasedArray3DSpecialCoordinatesImageTest)
itk_add_test(NAME itkPushPopTileImageFilterTest
Expand Down
Loading