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&#39;ve done many tests, even with sintentic images but so far I don&#39;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 &lt;conio.h&gt;<br>
#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkActiveShapeModelCalculator.h&quot; // .h and .txx files needed<br>#include &quot;itkActiveShapeModelGradientSearchMethod.h&quot; // .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 &lt; 3 )<br>    {<br>        std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>        std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; Input3DImageBinaryFile Input2DImageFile&quot; &lt;&lt; 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&lt;double&gt;                                              VectorOfDoubleType;<br>  typedef vnl_matrix&lt;double&gt;                                              MatrixOfDoubleType; <br>  typedef itk::Image&lt; PixelType, Dimension &gt;    Image3DType;<br>
  typedef itk::Image&lt; unsigned char, 2 &gt;    Image2DType;<br><br>  typedef itk::ImageFileReader&lt; Image3DType  &gt;  ReaderType;<br>  typedef itk::ActiveShapeModelCalculator&lt; Image3DType &gt; ActiveShapeModelCalculatorType;<br>
  typedef itk::ActiveShapeModelGradientSearchMethod&lt; Image2DType&gt; 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-&gt;SetFileName( inputFilename  );<br>
  inputImage = reader-&gt;GetOutput();<br>  reader-&gt;Update( );<br>  applyActiveShapeModelCalculator-&gt;SetImage( inputImage );  <br>  //----------------------------------------------------------------------<br>  //Set the parameters for ActiveShapeModelCalculator<br>
  //----------------------------------------------------------------------<br>  applyActiveShapeModelCalculator-&gt;SetTolerance( m_Tolerance );<br><br>  applyActiveShapeModelCalculator-&gt;SetUpperThresholdDistance(m_Thickness);<br>
<br>  applyActiveShapeModelCalculator-&gt;GenerateData();<br><br>  //Test the printself function to increase coverage<br>  applyActiveShapeModelCalculator-&gt;Print(std::cout);<br><br>  //Exercise TypeMacro in superclass<br>
  typedef ActiveShapeModelCalculatorType::Superclass GenericEstimatorType;<br>  std::cout &lt;&lt; applyActiveShapeModelCalculator-&gt;GenericEstimatorType::GetNameOfClass() &lt;&lt; std::endl;<br><br>  //Print out the number of training images and the number of principal <br>
  //components<br>  std::cout &lt;&lt; &quot;The number of training images are: &quot; &lt;&lt;<br>    applyActiveShapeModelCalculator-&gt;GetNumberOfTrainingImages() &lt;&lt; std::endl;<br><br>  std::cout &lt;&lt; &quot;The mean shape: &quot; &lt;&lt;<br>
    applyActiveShapeModelCalculator-&gt;GetMeanShape() &lt;&lt; std::endl;<br><br>  vnl_vector&lt;double&gt; eigenValues  =  applyActiveShapeModelCalculator-&gt;GetEigenvalues();<br>  vnl_matrix&lt;double&gt; eigenVectors =  applyActiveShapeModelCalculator-&gt;GetEigenvector();<br>
<br>  //Print the eigen values and eigen vectors<br>  std::cout &lt;&lt; &quot;The &quot; &lt;&lt; eigenValues.size() &lt;&lt; &quot; first values of the eigen vectors are:&quot; &lt;&lt; std::endl;<br>   for(unsigned int i = 0; i &lt; eigenVectors.rows(); i++) <br>
    {<br>    std::cout&lt;&lt; eigenVectors.get_row(i)&lt;&lt;&quot; &quot;;<br>    }  <br>  std::cout &lt;&lt;&quot;&quot;&lt;&lt;std::endl;<br>  std::cout &lt;&lt; &quot;The &quot; &lt;&lt; eigenValues.size() &lt;&lt; &quot; largest eigen values are:&quot; &lt;&lt; std::endl;<br>
  std::cout &lt;&lt; eigenValues &lt;&lt; std::endl;<br><br>  typedef itk::ImageFileReader&lt; Image2DType  &gt;  Reader2DType;<br>  Reader2DType::Pointer reader1 = Reader2DType::New();<br>  const char * input2DFilename  = argv[2];<br>
  reader1-&gt;SetFileName( input2DFilename  );<br>  reader1-&gt;Update( );<br><br>  ImageSearch-&gt;SetImage( reader1-&gt;GetOutput() );<br><br> //----------------------------------------------------------------------<br>
  //Set the parameters ActiveShapeModelSearchingImageFilter<br>  //----------------------------------------------------------------------<br>  ImageSearch-&gt;SetLenghtOfProfile( m_LenghtOfProfile );<br>  ImageSearch-&gt;SetNumberOfIteration( m_NumberOfIteration );<br>
  ImageSearch-&gt;SetMeanShape( applyActiveShapeModelCalculator-&gt;GetMeanShape() + 0.5);<br>  ImageSearch-&gt;SetEigenValues( applyActiveShapeModelCalculator-&gt;GetEigenvalues() );<br>  ImageSearch-&gt;SetEigenVectors( applyActiveShapeModelCalculator-&gt;GetEigenvector() );<br>
<br>  ImageSearch-&gt;GenerateData();<br><br>  //Test the printself function to increase coverage<br>  ImageSearch-&gt;Print(std::cout);<br><br>  //Exercise TypeMacro in superclass<br>  typedef ImageSearchType::Superclass GenericEstimator2Type;<br>
  std::cout &lt;&lt; ImageSearch-&gt;GenericEstimator2Type::GetNameOfClass() &lt;&lt; std::endl;<br><br>  std::cout &lt;&lt; &quot;The new shape: &quot; &lt;&lt;<br>  ImageSearch-&gt;GetNewShape() &lt;&lt; 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">&lt;<a href="mailto:sergio.vera@alma3d.com">sergio.vera@alma3d.com</a>&gt;</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&#39;ve wrapped the example of Active Shape Models (ASM) found in the example &quot;itkActiveShapeModelCalculatorTest.cxx&quot; 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>