[Insight-users] Re: MultiResMIRegistration

Luis Ibanez luis . ibanez at kitware . com
Wed, 28 Aug 2002 09:48:36 -0400


This is a multi-part message in MIME format.
--------------060303010903030609010002
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi Christina,

The error seems to be produced by line 94 of
MIMApplicationBase.cxx.

This line is catching a generic exception
whith "catch(...)". Because the exception can
be of any type, it is not printing any
description of possible source of the problem.

Please add the following lines before the
catch(...) statement in line 94:

   catch(itk::ExceptionObject & eo)
     {
     std::cout << "Error occured during registration" << std::endl;
     std::cout << eo << std::endl;
     }
   catch(std::exception & e)
     {
     std::cout << "Error occured during registration" << std::endl;
     std::cout << e.what() << std::endl;
     }


These lines will attempt to catch first an Itk exception,
then a standard exception and print out they potential
descriptions.

The messages produced should be clear enough to figure
out the source of the problem.

(Please find attached the same file with the corresponding
modifications, that may make things easier...).

Given that you are able to run up to level 3 in the
multiresolution registration, it is likely that the
problem is due to the moving image going out of the
range of the fixed image. If this is the case, you
may want to reduce the learning rate of the level 2
and 3 to prevent the transform from reaching large
displacements.


Please let us know what error message you get from
the exception.


Thanks


    Luis


====================================================

Christina Lee wrote:
> Hi Luis,
> 
> I wasn't able to run the multiresmiregistration
> program past level 3 & I got the following error
> messages:
> 
> "Error occurred during registration"
> "Caught an non-ITK exception"
> 
> What do these message imply? 
> 
> Thanks,
> 
> Christina
> 
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
> 
> 
> ------------------------------------------------------------------------
> 
> mr2_pre_masked.raw
>        0
>      512     512      52
>      0.664062     0.664062      7.00000
> mr2_hepatic_masked.raw
>        0
>      512     512      52
>      0.664062     0.664062      7.00000
>        0       1       2
>        0       0       0	
>        6
>        8       8       1
>        8       8       1
>     2500    2500    2500    2500    2500    2500
>   0.000320000 6.40000e-005 1.28000e-005 2.56000e-006 5.12000e-007 1.02400e-007
>      320 
> pgmsdir1
>        
> 



--------------060303010903030609010002
Content-Type: text/plain;
 name="MIMApplicationBase.txx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="MIMApplicationBase.txx"

/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: MIMApplicationBase.txx,v $
  Language:  C++
  Date:      $Date: 2002/03/15 05:59:53 $
  Version:   $Revision: 1.1 $

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef _MIMApplicationBase_txx
#define _MIMApplicationBase_txx

#include "MIMApplicationBase.h"

namespace itk
{

template < typename TInputImage, typename TImage,
  typename TParser, typename TPreprocessor,
  typename TRegistrator, typename TGenerator >
MIMApplicationBase<TInputImage,TImage,TParser,TPreprocessor,
  TRegistrator, TGenerator>
::MIMApplicationBase()
{
  m_Parser       = ParserType::New();
  m_Preprocessor = PreprocessorType::New();
  m_Registrator  = RegistratorType::New();
  m_Generator    = GeneratorType::New();

  m_Transform    = AffineTransformType::New();
}


template < typename TInputImage, typename TImage,
  typename TParser, typename TPreprocessor,
  typename TRegistrator, typename TGenerator >
void
MIMApplicationBase<TInputImage,TImage,TParser,TPreprocessor,
  TRegistrator, TGenerator>
::Execute()
{

  /**************************
   * Parse input
   **************************/
  std::cout << "Parsing input ... " << std::endl;
  
  try
    {
    this->InitializeParser();
    m_Parser->Execute();
    }
  catch(itk::ExceptionObject & eo)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "itk::ExceptionObject caught" << std::endl;
    std::cout << eo << std::endl;
    throw;
    }
  catch(std::exception & e)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "std::exception caught" << std::endl;
    std::cout << e.what() << std::endl;
    throw;
    }
  catch(...)
   {
   std::cout << "Error occurred during input parsing." << std::endl;
   throw;
   }

  /**************************
   * Preprocess the images before registration
   **************************/

  std::cout << "Preprocess the images ... " << std::endl;

  try
    {
    this->InitializePreprocessor();
    m_Preprocessor->Execute();
    }
  catch(itk::ExceptionObject & eo)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "itk::ExceptionObject caught" << std::endl;
    std::cout << eo << std::endl;
    throw;
    }
  catch(std::exception & e)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "std::exception caught" << std::endl;
    std::cout << e.what() << std::endl;
    throw;
    }
  catch(...)
    {
    std::cout << "Error occured during preprocessing." << std::endl;
    throw;
    }


  /**************************
   * Registered the processed images
   **************************/
  std::cout << "Register the images ... " << std::endl;

  try
    {
    this->InitializeRegistrator();
    m_Registrator->Execute();
    }
  catch(itk::ExceptionObject & eo)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "itk::ExceptionObject caught" << std::endl;
    std::cout << eo << std::endl;
    throw;
    }
  catch(std::exception & e)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "std::exception caught" << std::endl;
    std::cout << e.what() << std::endl;
    throw;
    }
  catch(...)
    {
    std::cout << "Error occured during registration" << std::endl;
    throw;
    }

  // Get the results
  std::cout << "Final parameters: " 
            << m_Registrator->GetTransformParameters() << std::endl;


  /***************************
   * Compute overall transform
   ***************************/
  // compose the preprocess and registration transforms
  m_Transform->SetIdentity();
  m_Transform->Compose( m_Preprocessor->GetPostTransform(), true );
  m_Transform->Compose( m_Registrator->GetAffineTransform(), true );
  m_Transform->Compose( m_Preprocessor->GetPreTransform(), true );

  std::cout << "Overall transform matrix: " << std::endl;
  std::cout << m_Transform->GetMatrix() << std::endl;
  std::cout << "Overall transform offset: " << std::endl;
  std::cout << m_Transform->GetOffset() << std::endl;


  /**************************
   * Generating output
   **************************/
  std::cout << "Generating output ... " << std::endl;
  
  try
    {
    this->InitializeGenerator();
    m_Generator->Execute();
    }
  catch(itk::ExceptionObject & eo)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "itk::ExceptionObject caught" << std::endl;
    std::cout << eo << std::endl;
    throw;
    }
  catch(std::exception & e)
    {
    std::cout << "Error occured during registration" << std::endl;
    std::cout << "std::exception caught" << std::endl;
    std::cout << e.what() << std::endl;
    throw;
    }
  catch(...)
   {
   std::cout << "Error occurred during output generation." << std::endl;
   throw;
   }

}


template < typename TInputImage, typename TImage,
  typename TParser, typename TPreprocessor,
  typename TRegistrator, typename TGenerator >
void
MIMApplicationBase<TInputImage,TImage,TParser,TPreprocessor,
  TRegistrator, TGenerator>
::InitializePreprocessor()
{
  m_Preprocessor->SetInputFixedImage( m_Parser->GetFixedImage() );
  m_Preprocessor->SetInputMovingImage( m_Parser->GetMovingImage() );

  m_Preprocessor->SetPermuteOrder( m_Parser->GetPermuteOrder() );
  m_Preprocessor->SetFlipAxes( m_Parser->GetFlipAxes() );
}


template < typename TInputImage, typename TImage,
  typename TParser, typename TPreprocessor,
  typename TRegistrator, typename TGenerator >
void
MIMApplicationBase<TInputImage,TImage,TParser,TPreprocessor,
  TRegistrator, TGenerator>
::InitializeRegistrator()
{

  // connect the images
  m_Registrator->SetFixedImage( m_Preprocessor->GetOutputFixedImage() );
  m_Registrator->SetMovingImage( m_Preprocessor->GetOutputMovingImage() );

  // set multiresolution related parameters
  m_Registrator->SetNumberOfLevels( m_Parser->GetNumberOfLevels() );

  m_Registrator->SetFixedImageShrinkFactors( m_Parser->GetFixedImageShrinkFactors() );

  // permute the shrink factors
  unsigned int permutedFactors[ImageDimension];
  for ( int j = 0; j < ImageDimension; j++ )
    {
    permutedFactors[j] = m_Parser->GetMovingImageShrinkFactors()[
      m_Parser->GetPermuteOrder()[j] ];
    }
  m_Registrator->SetMovingImageShrinkFactors( permutedFactors );

  m_Registrator->SetNumberOfIterations( m_Parser->GetNumberOfIterations() );
  m_Registrator->SetLearningRates( m_Parser->GetLearningRates() );

  double scale = 1.0 / vnl_math_sqr( m_Parser->GetTranslationScale() );
  m_Registrator->SetTranslationScale( scale );

}

} // namespace itk

#endif



--------------060303010903030609010002--