Skip to content
Snippets Groups Projects
Commit f8b93ba7 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

BUG: 552: add a second pass to mask pixels outside the deformation grid

parent 5ac087fe
No related branches found
No related tags found
No related merge requests found
......@@ -260,8 +260,8 @@ StereorectificationDeformationFieldSource<TInputImage, TOutputImage>
// And also the size of the deformation field
SizeType outputSize;
outputSize[0] = (m_RectifiedImageSize[0] / m_GridStep + 1 );
outputSize[1] = (m_RectifiedImageSize[1] / m_GridStep + 1);
outputSize[0] = (m_RectifiedImageSize[0] / m_GridStep + 2 );
outputSize[1] = (m_RectifiedImageSize[1] / m_GridStep + 2);
// Build the output largest region
RegionType outputLargestRegion;
......
......@@ -64,10 +64,15 @@ public:
typedef TInputImage InputImageType;
typedef typename InputImageType::Pointer InputImagePointerType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::PointType PointType;
typedef typename OutputImageType::IndexType IndexType;
typedef typename OutputImageType::PixelType PixelType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef TDeformationField DeformationFieldType;
typedef typename DeformationFieldType::PixelType DeformationValueType;
typedef typename DeformationFieldType::Pointer DeformationFieldPointerType;
typedef typename DeformationFieldType::RegionType DeformationFieldRegionType;
/** Accessors */
itkSetMacro(MaximumDeformation, DeformationValueType);
......@@ -85,6 +90,12 @@ protected:
* produce its output. As such, we need to overload the GenerateInputRequestedRegion() method.
*/
virtual void GenerateInputRequestedRegion();
/**
* Re-implement the method ThreadedGenerateData to mask area outside the deformation grid
*/
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId );
private:
StreamingWarpImageFilter(const Self &); //purposely not implemented
......
......@@ -202,6 +202,52 @@ StreamingWarpImageFilter<TInputImage, TOutputImage, TDeformationField>
}
}
template<class TInputImage, class TOutputImage, class TDeformationField>
void
StreamingWarpImageFilter<TInputImage, TOutputImage, TDeformationField>
::ThreadedGenerateData(
const OutputImageRegionType& outputRegionForThread,
int threadId )
{
// the superclass itk::WarpImageFilter is doing the actual warping
Superclass::ThreadedGenerateData(outputRegionForThread,threadId);
// second pass on the thread region to mask pixels outside the deformation grid
const PixelType paddingValue = this->GetEdgePaddingValue();
OutputImagePointerType outputPtr = this->GetOutput();
DeformationFieldPointerType fieldPtr = this->GetDeformationField();
DeformationFieldRegionType defRegion = fieldPtr->GetLargestPossibleRegion();
itk::ImageRegionIteratorWithIndex<OutputImageType> outputIt(
outputPtr, outputRegionForThread );
IndexType currentIndex;
PointType currentPoint;
itk::ContinuousIndex<double,DeformationFieldType::ImageDimension> contiIndex;
while(!outputIt.IsAtEnd())
{
// get the output image index
currentIndex = outputIt.GetIndex();
outputPtr->TransformIndexToPhysicalPoint(currentIndex,currentPoint);
fieldPtr->TransformPhysicalPointToContinuousIndex(currentPoint,contiIndex);
for (unsigned int dim = 0; dim<DeformationFieldType::ImageDimension; ++dim)
{
if (contiIndex[dim] < static_cast<double>(defRegion.GetIndex(dim)) ||
contiIndex[dim] > static_cast<double>(defRegion.GetIndex(dim)+defRegion.GetSize(dim)-1))
{
outputIt.Set(paddingValue);
break;
}
}
++outputIt;
}
}
template<class TInputImage, class TOutputImage, class TDeformationField>
void
StreamingWarpImageFilter<TInputImage, TOutputImage, TDeformationField>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment