[Insight-users] Crash when estimating the inverse of a BSpline transform.

lien lee lienlee at gmail.com
Wed Oct 31 12:18:25 EDT 2012


Hi all,

By referring to "itkInverseDisplacementFieldImageFilterTest.cxx", I tried
the following code piece for estimating the inverse of a BSpline transform
through using itk::InverseDisplacementFieldImageFilter.

However, the code crashes on the line
"vFilter->UpdateLargestPossibleRegion();"

Please point me the reason, thanks!


//====== Start of the code piece ===========================================
void InvertBSpline(const ImageType::Pointer vMovImg, const
ImageType::Pointer vFixImg, const BSplineDeformableTransform::Pointer
vTransform)
{
    typedef itk::Vector<float,3>        VectorType;
    typedef itk::Image<VectorType, 3>   DisplacementFieldType;
    DisplacementFieldType::Pointer vDisplacementField =
DisplacementFieldType::New();
    vDisplacementField->CopyInformation(vFixImg);
    vDisplacementField->Allocate();
    typedef itk::ImageRegionIteratorWithIndex<ItkRawType> FixIteratorType;
    typedef itk::ImageRegionIteratorWithIndex<DisplacementFieldType>
DisIteratorType;
    FixIteratorType itFix(vFixImg, vFixImg->GetRequestedRegion());
    DisIteratorType itDis(vDisplacementField,
vDisplacementField->GetRequestedRegion());
    for (itFix.GoToBegin(), itDis.GoToBegin(); !itFix.IsAtEnd(); ++itFix,
++itDis)
    {
        ImageType::IndexType idx = itFix.GetIndex();
        itk::Point<double,3> vFixPoint, vMovPoint;
        vFixImg->TransformIndexToPhysicalPoint(idx, vFixPoint);
        vMovPoint = vTransform->TransformPoint(vFixPoint);
        VectorType vTmp;
        vTmp[0] = vMovPoint[0] - vFixPoint[0];
        vTmp[1] = vMovPoint[1] - vFixPoint[1];
        vTmp[2] = vMovPoint[2] - vFixPoint[2];
        itDis.Set(vTmp);
    }

    //- Create inverse displacement filter
    //
    typedef itk::InverseDisplacementFieldImageFilter<
                                    DisplacementFieldType,
                                    DisplacementFieldType>  FilterType;
    FilterType::Pointer vFilter = FilterType::New();
    vFilter->SetOutputSpacing(vMovImg->GetSpacing());
    vFilter->SetOutputOrigin(vMovImg->GetOrigin());
    vFilter->SetSize(vMovImg->GetLargestPossibleRegion().GetSize());
    vFilter->SetInput(vDisplacementField);
    vFilter->SetSubsamplingFactor(16);

    try
    {
        vFilter->UpdateLargestPossibleRegion();
    }
    catch( itk::ExceptionObject & excp )
    {
        std::cerr << "Exception thrown " << std::endl;
        std::cerr << excp << std::endl;
    }
}

//====== End of the code piece =============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121031/48c62e96/attachment.htm>


More information about the Insight-users mailing list