[Insight-users] Cannot run the Resampling filter
motes motes
mort.motes at gmail.com
Thu Nov 26 13:58:30 EST 2009
On Thu, Nov 26, 2009 at 7:42 PM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Motes,
>
>
> 1) The Scope of the "try" block doesn't destroy any of the
> components of the registration framework.
>
Ok that was also my understanding.
>
> 2) I don't see how you are passing any arguments to the
> function:
>
> computeRegisteredImage();
>
> are you declaring them as global ?
>
>
Yes the registration components and images are "global" fields in a
wrapper class that I have written.
> 3) No offense,
> but your custom Transform is the main suspect.
>
> Here is the important question:
>
>
> Have you written a Unit Test
> for your new Transform ?
>
>
> I can anticipate that the answer is "no", :-)
>
> and therefore
>
> I will strongly,
> very, very, very strongly suggest
>
> that you write such unit test and fully debug
> your transform before you attempt to use it
> as part of a larger program.
>
> For examples on how to test Transforms,
> Please look at the files
>
> Insight/Testing/Code/Common/
>
> itkAffineTransformTest.cxx
> itkAzimuthElevationToCartesianTransformTest.cxx
> itkBSplineDeformableTransformTest2.cxx
> itkBSplineDeformableTransformTest.cxx
> itkCenteredAffineTransformTest.cxx
> itkCenteredEuler3DTransformTest.cxx
> itkCenteredRigid2DTransformTest.cxx
> itkCenteredTransformInitializerTest.cxx
> itkCenteredVersorTransformInitializerTest.cxx
> itkEuler2DTransformTest.cxx
> itkEuler3DTransformTest.cxx
> itkFixedCenterOfRotationAffineTransformTest.cxx
> itkIdentityTransformTest.cxx
> itkImageTransformTest.cxx
> itkLandmarkBasedTransformInitializerTest.cxx
> itkQuaternionRigidTransformTest.cxx
> itkRigid2DTransformTest.cxx
> itkRigid3DPerspectiveTransformTest.cxx
> itkRigid3DTransformTest.cxx
> itkRigid3DTransformTest.cxx.orig
> itkScaleLogarithmicTransformTest.cxx
> itkScaleSkewVersor3DTransformTest.cxx
> itkScaleTransformTest.cxx
> itkSimilarity2DTransformTest.cxx
> itkSimilarity3DTransformTest.cxx
> itkSplineKernelTransformTest.cxx
> itkTransformsSetParametersTest.cxx
> itkTransformTest.cxx
> itkTranslationTransformTest.cxx
> itkVersorRigid3DTransformTest.cxx
> itkVersorTransformTest.cxx
>
>
>
Actually all new code I write is done through unit-tests. But thanks
for the above suggestions!
> Regards,
>
>
> Luis
>
>
> ------------------------------------------------------------------------------------------
> On Wed, Nov 25, 2009 at 8:44 PM, motes motes <mort.motes at gmail.com> wrote:
>> Which objects survive in the transform component when the image
>> registration method is finished?
>>
>> By finished I mean reaches the scope after this try/catch block:
>>
>> try {
>> registration->Update();
>> }
>> catch( itk::ExceptionObject & err ) {
>> std::cerr << "ExceptionObject caught !" << std::endl;
>> std::cerr << err << std::endl;
>> return EXIT_FAILURE;
>> }
>>
>> // What lives in the image registration method when arriving here?
>>
>>
>>
>>
>>
>> The reason I ask is because I am trying to compute the registered
>> image AFTER the registration method is done. Something like this:
>>
>> try {
>>
>> registration->Update();
>> }
>> catch( itk::ExceptionObject & err ) {
>> std::cerr << "ExceptionObject caught !" << std::endl;
>> std::cerr << err << std::endl;
>> return EXIT_FAILURE;
>> }
>>
>> computeRegisteredImage();
>> return EXIT_SUCCESS;
>>
>>
>> where:
>>
>> void computeRegisteredImage(){
>> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
>> resampler->SetInput(imageM);
>> resampler->SetTransform(registration->GetTransform());
>> resampler->SetInterpolator(registration->GetInterpolator());
>> resampler->SetOutputOrigin(imageF->GetOrigin());
>> resampler->SetOutputSpacing(imageF->GetSpacing());
>> resampler->SetSize(imageF->GetLargestPossibleRegion().GetSize());
>> resampler->SetDefaultPixelValue(default_pixel_value);
>> try {
>> resampler->Update();
>> }
>> catch( itk::ExceptionObject & err ) {
>> std::cerr << "ExceptionObject caught !" << std::endl;
>> std::cerr << err << std::endl;
>> }
>>
>>
>> imageR = resampler->GetOutput();
>>
>>
>> }
>>
>>
>>
>> But:
>>
>> resampler->Update();
>>
>> never returns. It thows a segmentation fault. I have located the error
>> to be in the TransformPoint method. I have made my own transform which
>> uses a kdTree in the TransformPoint function. This kdTree is stored
>> locally in my transform like:
>>
>>
>> #include "kd_tree.h" // My own itk:kdTree wrapper.
>> namespace itk
>> {
>> template <
>> class TScalarType = double, // Data type for scalars
>> unsigned int NDimensions = 3, // Number of dimensions
>> unsigned int VSplineOrder = 3 > // Spline order
>> class ITK_EXPORT MyDeformableTransform :
>> public Transform< TScalarType, NDimensions, NDimensions >
>> {
>> public:
>> /** Standard class typedefs. */
>> typedef MyDeformableTransform Self;
>> ...
>> ...
>> ...
>>
>> typedef KdTree<VectorType, ControlPointContainerType, NDimensions>
>> KdTreeType;
>>
>>
>> ....
>> .....
>> ...
>> protected:
>> mutable KdTreeType m_kdTree;
>>
>>
>>
>>
>>
>> Can this have something to do with the segmentation error? Does it
>> need to be stored as a smart pointer instead?
>>
>>
>>
>>
>>
>>
>>
>> In the TransformPoint function I do:
>>
>> // Transform a point
>> template<class TScalarType, unsigned int NDimensions, unsigned int VSplineOrder>
>> void
>> MyDeformableTransform<TScalarType, NDimensions, VSplineOrder>
>> ::TransformPoint(
>> const InputPointType & point,
>> OutputPointType & outputPoint,
>> WeightsType & weights,
>> ParameterIndexArrayType & indices,
>> bool & inside ) const
>> {
>> unsigned int j;
>> IndexType supportIndex;
>> inside = true;
>> InputPointType transformedPoint;
>>
>> if ( m_BulkTransform ) {
>> transformedPoint = m_BulkTransform->TransformPoint( point );
>> } else {
>> transformedPoint = point;
>> }
>>
>> outputPoint.Fill( NumericTraits<ScalarType>::Zero );
>> if ( GetNumberOfParameters()>0) {
>> outputPoint.Fill( NumericTraits<ScalarType>::Zero );
>>
>>
>>
>> NeighborContainerType neighbors;
>>
>> // This results in a segmentation error
>> this->FindNeighbors(point, m_kernel_radius, neighbors);
>>
>>
>>
>> its the call:
>>
>> this->FindNeighbors(point, m_kernel_radius, neighbors);
>>
>> that gives the error which basically just calls the itk::kdTree class.
>>
>> Any suggestions are most welcome!
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>
More information about the Insight-users
mailing list