[Insight-users] weird behavior of ActiveShapeModelGradientSearchMethod related with number of iterations
Sergio Vera
sergio.vera at alma3d.com
Wed Feb 17 05:32:06 EST 2010
Well, after a couple of days analyzing the code I cannot find the cause of
the problem.
At the training stage and using default values, the
ActiveShapeModelCalculator does not generate a valid model (0
eigenvectors/eigenvalues are extracted from the model). This can be solved
by changing the ActiveShapeModelCalculator::SetUpperThresholdDistance() from
the default 1 to 0.8. Changing this value, 3 eigenvectors are extracted.
However, at the searching stage, the algorithm seems to diverge:
ActiveShapeModelGradientSearchMethod starts to move far from the target
region, as iterations increase, escaping from the image. I've done many
tests, even with sintentic images but so far I don't know why this happens.
Could someone try the code with the supplied example images and see if they
experiment the same behavior?
Many thanks
// CODE--------------------------------------------------------
#include <conio.h>
#include "itkImageFileReader.h"
#include "itkActiveShapeModelCalculator.h" // .h and .txx files needed
#include "itkActiveShapeModelGradientSearchMethod.h" // .h and .txx files
needed
int itkActiveShapeModelCalculatorTest(int, char*[]);
int
main(int argc, char* argv[])
{
exit(itkActiveShapeModelCalculatorTest(argc,argv));
}
int itkActiveShapeModelCalculatorTest( int argc, char * argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " Input3DImageBinaryFile Input2DImageFile"
<< std::endl;
return -1;
}
// ------ALGORITHM PARAMETERS------
const unsigned int Dimension = 3;
const float m_Tolerance = 2.0;
const float m_Thickness = 0.8; // devault value (1)
does not generate a valid model (0 eigenvectors)!!!!
const unsigned int m_LenghtOfProfile = 3;
const unsigned int m_NumberOfIteration = 2; // increasing this
value ends with a sliding shape and an app crash!!!!!!
typedef float PixelType;
typedef vnl_vector<double>
VectorOfDoubleType;
typedef vnl_matrix<double>
MatrixOfDoubleType;
typedef itk::Image< PixelType, Dimension > Image3DType;
typedef itk::Image< unsigned char, 2 > Image2DType;
typedef itk::ImageFileReader< Image3DType > ReaderType;
typedef itk::ActiveShapeModelCalculator< Image3DType >
ActiveShapeModelCalculatorType;
typedef itk::ActiveShapeModelGradientSearchMethod< Image2DType>
ImageSearchType;
ActiveShapeModelCalculatorType::Pointer
applyActiveShapeModelCalculator = ActiveShapeModelCalculatorType::New();
ImageSearchType::Pointer
ImageSearch = ImageSearchType::New();
ReaderType::Pointer reader = ReaderType::New();
Image3DType::ConstPointer inputImage;
const char * inputFilename = argv[1];
reader->SetFileName( inputFilename );
inputImage = reader->GetOutput();
reader->Update( );
applyActiveShapeModelCalculator->SetImage( inputImage );
//----------------------------------------------------------------------
//Set the parameters for ActiveShapeModelCalculator
//----------------------------------------------------------------------
applyActiveShapeModelCalculator->SetTolerance( m_Tolerance );
applyActiveShapeModelCalculator->SetUpperThresholdDistance(m_Thickness);
applyActiveShapeModelCalculator->GenerateData();
//Test the printself function to increase coverage
applyActiveShapeModelCalculator->Print(std::cout);
//Exercise TypeMacro in superclass
typedef ActiveShapeModelCalculatorType::Superclass GenericEstimatorType;
std::cout <<
applyActiveShapeModelCalculator->GenericEstimatorType::GetNameOfClass() <<
std::endl;
//Print out the number of training images and the number of principal
//components
std::cout << "The number of training images are: " <<
applyActiveShapeModelCalculator->GetNumberOfTrainingImages() <<
std::endl;
std::cout << "The mean shape: " <<
applyActiveShapeModelCalculator->GetMeanShape() << std::endl;
vnl_vector<double> eigenValues =
applyActiveShapeModelCalculator->GetEigenvalues();
vnl_matrix<double> eigenVectors =
applyActiveShapeModelCalculator->GetEigenvector();
//Print the eigen values and eigen vectors
std::cout << "The " << eigenValues.size() << " first values of the eigen
vectors are:" << std::endl;
for(unsigned int i = 0; i < eigenVectors.rows(); i++)
{
std::cout<< eigenVectors.get_row(i)<<" ";
}
std::cout <<""<<std::endl;
std::cout << "The " << eigenValues.size() << " largest eigen values are:"
<< std::endl;
std::cout << eigenValues << std::endl;
typedef itk::ImageFileReader< Image2DType > Reader2DType;
Reader2DType::Pointer reader1 = Reader2DType::New();
const char * input2DFilename = argv[2];
reader1->SetFileName( input2DFilename );
reader1->Update( );
ImageSearch->SetImage( reader1->GetOutput() );
//----------------------------------------------------------------------
//Set the parameters ActiveShapeModelSearchingImageFilter
//----------------------------------------------------------------------
ImageSearch->SetLenghtOfProfile( m_LenghtOfProfile );
ImageSearch->SetNumberOfIteration( m_NumberOfIteration );
ImageSearch->SetMeanShape( applyActiveShapeModelCalculator->GetMeanShape()
+ 0.5);
ImageSearch->SetEigenValues(
applyActiveShapeModelCalculator->GetEigenvalues() );
ImageSearch->SetEigenVectors(
applyActiveShapeModelCalculator->GetEigenvector() );
ImageSearch->GenerateData();
//Test the printself function to increase coverage
ImageSearch->Print(std::cout);
//Exercise TypeMacro in superclass
typedef ImageSearchType::Superclass GenericEstimator2Type;
std::cout << ImageSearch->GenericEstimator2Type::GetNameOfClass() <<
std::endl;
std::cout << "The new shape: " <<
ImageSearch->GetNewShape() << std::endl;
// Software Guide : BeginCodeSnippet
// Software Guide : EndCodeSnippet
return 0;
}
On Thu, Feb 11, 2010 at 5:55 PM, Sergio Vera <sergio.vera at alma3d.com> wrote:
> Hello!
>
> I've wrapped the example of Active Shape Models (ASM) found in the example
> "itkActiveShapeModelCalculatorTest.cxx" with a small gui to be able to play
> with the tolerance, iteration and profilelenght values.
> Using the supplied model.mha and feet.mha images, the program runs smoothly
> and generates a reasonably correct mean shape:
>
> However, with the 2 iterations shown in the example cxx file, in the
> ActiveShapeModelGradientSearchMethod the process does not segment correctly
> the image. When incrementing the iteration steps, the result seems strange
> to me.
> The resulting polygon (that starts reasonably close to the target bone),
> does not seems to deformate or adapt to the input image at all, and only
> seems to move out of the image as iterations increase.
>
> At 20 iterations the polygon is starting to be outside the image, with a
> couple of vertex with negative x values, and at 21 iterations the
> coordinates of the resulting polygon have skyrocketed to the order of
> hundreds of millions of pixels.
> At 22 iterations the application crashes.
>
> Does any of you has experienced a similar behavior with this example?
> Any clue for what may be happening?
>
> Regards
>
> Sergio
>
>
--
Sergio Vera
Alma IT Systems
C/ Vilana, 4B, 4º 1ª
08022 Barcelona
T. (+34) 932 380 592
www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100217/00f4267c/attachment-0001.htm>
More information about the Insight-users
mailing list