Well, after a couple of days analyzing the code I cannot find the cause of the problem.<br><br>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.<br>
<br>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.<br>
<br>Could someone try the code with the supplied example images and see if they experiment the same behavior?<br>Many thanks<br><br>// CODE--------------------------------------------------------<br>#include <conio.h><br>
#include "itkImageFileReader.h"<br>#include "itkActiveShapeModelCalculator.h" // .h and .txx files needed<br>#include "itkActiveShapeModelGradientSearchMethod.h" // .h and .txx files needed<br>
<br>int itkActiveShapeModelCalculatorTest(int, char*[]);<br>int<br>main(int argc, char* argv[]) <br>{<br> exit(itkActiveShapeModelCalculatorTest(argc,argv));<br>}<br><br>int itkActiveShapeModelCalculatorTest( int argc, char * argv[] )<br>
{<br> if( argc < 3 )<br> {<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " Input3DImageBinaryFile Input2DImageFile" << std::endl;<br>
return -1;<br> }<br>// ------ALGORITHM PARAMETERS------<br> const unsigned int Dimension = 3;<br> const float m_Tolerance = 2.0;<br> const float m_Thickness = 0.8; // devault value (1) does not generate a valid model (0 eigenvectors)!!!!<br>
const unsigned int m_LenghtOfProfile = 3;<br> const unsigned int m_NumberOfIteration = 2; // increasing this value ends with a sliding shape and an app crash!!!!!!<br><br><br> typedef float PixelType;<br>
typedef vnl_vector<double> VectorOfDoubleType;<br> typedef vnl_matrix<double> MatrixOfDoubleType; <br> typedef itk::Image< PixelType, Dimension > Image3DType;<br>
typedef itk::Image< unsigned char, 2 > Image2DType;<br><br> typedef itk::ImageFileReader< Image3DType > ReaderType;<br> typedef itk::ActiveShapeModelCalculator< Image3DType > ActiveShapeModelCalculatorType;<br>
typedef itk::ActiveShapeModelGradientSearchMethod< Image2DType> ImageSearchType;<br> ActiveShapeModelCalculatorType::Pointer <br> applyActiveShapeModelCalculator = ActiveShapeModelCalculatorType::New();<br> ImageSearchType::Pointer <br>
ImageSearch = ImageSearchType::New();<br> ReaderType::Pointer reader = ReaderType::New();<br> Image3DType::ConstPointer inputImage;<br><br> const char * inputFilename = argv[1];<br> reader->SetFileName( inputFilename );<br>
inputImage = reader->GetOutput();<br> reader->Update( );<br> applyActiveShapeModelCalculator->SetImage( inputImage ); <br> //----------------------------------------------------------------------<br> //Set the parameters for ActiveShapeModelCalculator<br>
//----------------------------------------------------------------------<br> applyActiveShapeModelCalculator->SetTolerance( m_Tolerance );<br><br> applyActiveShapeModelCalculator->SetUpperThresholdDistance(m_Thickness);<br>
<br> applyActiveShapeModelCalculator->GenerateData();<br><br> //Test the printself function to increase coverage<br> applyActiveShapeModelCalculator->Print(std::cout);<br><br> //Exercise TypeMacro in superclass<br>
typedef ActiveShapeModelCalculatorType::Superclass GenericEstimatorType;<br> std::cout << applyActiveShapeModelCalculator->GenericEstimatorType::GetNameOfClass() << std::endl;<br><br> //Print out the number of training images and the number of principal <br>
//components<br> std::cout << "The number of training images are: " <<<br> applyActiveShapeModelCalculator->GetNumberOfTrainingImages() << std::endl;<br><br> std::cout << "The mean shape: " <<<br>
applyActiveShapeModelCalculator->GetMeanShape() << std::endl;<br><br> vnl_vector<double> eigenValues = applyActiveShapeModelCalculator->GetEigenvalues();<br> vnl_matrix<double> eigenVectors = applyActiveShapeModelCalculator->GetEigenvector();<br>
<br> //Print the eigen values and eigen vectors<br> std::cout << "The " << eigenValues.size() << " first values of the eigen vectors are:" << std::endl;<br> for(unsigned int i = 0; i < eigenVectors.rows(); i++) <br>
{<br> std::cout<< eigenVectors.get_row(i)<<" ";<br> } <br> std::cout <<""<<std::endl;<br> std::cout << "The " << eigenValues.size() << " largest eigen values are:" << std::endl;<br>
std::cout << eigenValues << std::endl;<br><br> typedef itk::ImageFileReader< Image2DType > Reader2DType;<br> Reader2DType::Pointer reader1 = Reader2DType::New();<br> const char * input2DFilename = argv[2];<br>
reader1->SetFileName( input2DFilename );<br> reader1->Update( );<br><br> ImageSearch->SetImage( reader1->GetOutput() );<br><br> //----------------------------------------------------------------------<br>
//Set the parameters ActiveShapeModelSearchingImageFilter<br> //----------------------------------------------------------------------<br> ImageSearch->SetLenghtOfProfile( m_LenghtOfProfile );<br> ImageSearch->SetNumberOfIteration( m_NumberOfIteration );<br>
ImageSearch->SetMeanShape( applyActiveShapeModelCalculator->GetMeanShape() + 0.5);<br> ImageSearch->SetEigenValues( applyActiveShapeModelCalculator->GetEigenvalues() );<br> ImageSearch->SetEigenVectors( applyActiveShapeModelCalculator->GetEigenvector() );<br>
<br> ImageSearch->GenerateData();<br><br> //Test the printself function to increase coverage<br> ImageSearch->Print(std::cout);<br><br> //Exercise TypeMacro in superclass<br> typedef ImageSearchType::Superclass GenericEstimator2Type;<br>
std::cout << ImageSearch->GenericEstimator2Type::GetNameOfClass() << std::endl;<br><br> std::cout << "The new shape: " <<<br> ImageSearch->GetNewShape() << std::endl;<br><br>
// Software Guide : BeginCodeSnippet<br> // Software Guide : EndCodeSnippet<br> return 0;<br>}<br><br><div class="gmail_quote">On Thu, Feb 11, 2010 at 5:55 PM, Sergio Vera <span dir="ltr"><<a href="mailto:sergio.vera@alma3d.com">sergio.vera@alma3d.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello!<br><br>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.<br>
Using the supplied model.mha and feet.mha images, the program runs smoothly and generates a reasonably correct mean shape:<br><br>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.<br>
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.<br><br>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.<br>
At 22 iterations the application crashes.<br><br>Does any of you has experienced a similar behavior with this example?<br>Any clue for what may be happening?<br><br>Regards<br><font color="#888888"><br>Sergio<br><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Sergio Vera<br><br> Alma IT Systems<br> C/ Vilana, 4B, 4º 1ª<br> 08022 Barcelona<br> T. (+34) 932 380 592<br> <a href="http://www.alma3d.com">www.alma3d.com</a><br>