Hi all,<br><br>By referring to "itkInverseDisplacementFieldImageFilterTest.cxx", I tried the following code piece for estimating the inverse of a BSpline transform through using itk::InverseDisplacementFieldImageFilter. <br>
<br>However, the code crashes on the line <br>"vFilter->UpdateLargestPossibleRegion();"<br><br>Please point me the reason, thanks!<br><br><br>//====== Start of the code piece ===========================================<br>
void InvertBSpline(const ImageType::Pointer vMovImg, const ImageType::Pointer vFixImg, const BSplineDeformableTransform::Pointer vTransform)<br>{<br> typedef itk::Vector<float,3> VectorType;<br> typedef itk::Image<VectorType, 3> DisplacementFieldType;<br>
DisplacementFieldType::Pointer vDisplacementField = DisplacementFieldType::New();<br> vDisplacementField->CopyInformation(vFixImg);<br> vDisplacementField->Allocate();<br> typedef itk::ImageRegionIteratorWithIndex<ItkRawType> FixIteratorType;<br>
typedef itk::ImageRegionIteratorWithIndex<DisplacementFieldType> DisIteratorType;<br> FixIteratorType itFix(vFixImg, vFixImg->GetRequestedRegion());<br> DisIteratorType itDis(vDisplacementField, vDisplacementField->GetRequestedRegion());<br>
for (itFix.GoToBegin(), itDis.GoToBegin(); !itFix.IsAtEnd(); ++itFix, ++itDis)<br> {<br> ImageType::IndexType idx = itFix.GetIndex();<br> itk::Point<double,3> vFixPoint, vMovPoint;<br> vFixImg->TransformIndexToPhysicalPoint(idx, vFixPoint);<br>
vMovPoint = vTransform->TransformPoint(vFixPoint);<br> VectorType vTmp;<br> vTmp[0] = vMovPoint[0] - vFixPoint[0];<br> vTmp[1] = vMovPoint[1] - vFixPoint[1];<br> vTmp[2] = vMovPoint[2] - vFixPoint[2];<br>
itDis.Set(vTmp);<br> }<br><br> //- Create inverse displacement filter<br> //<br> typedef itk::InverseDisplacementFieldImageFilter<<br> DisplacementFieldType,<br> DisplacementFieldType> FilterType;<br>
FilterType::Pointer vFilter = FilterType::New();<br> vFilter->SetOutputSpacing(vMovImg->GetSpacing());<br> vFilter->SetOutputOrigin(vMovImg->GetOrigin());<br> vFilter->SetSize(vMovImg->GetLargestPossibleRegion().GetSize());<br>
vFilter->SetInput(vDisplacementField);<br> vFilter->SetSubsamplingFactor(16);<br><br> try<br> {<br> vFilter->UpdateLargestPossibleRegion();<br> }<br> catch( itk::ExceptionObject & excp )<br>
{<br> std::cerr << "Exception thrown " << std::endl;<br> std::cerr << excp << std::endl;<br> }<br>}<br><br>//====== End of the code piece =============================================<br>
<br>