Hi all,<br><br>I would like to use the very usefull ITK classes to segment mammographic images with level set methods.<br>In order to learn these classes, I run properly the examples provided with the library and explained in the software guide.<br>
Therefore, I&#39;ve tried to apply the filter ShapeDetectionLevelSetImageFilter to a very simple circular model,<br>but I cannot obtain any reasonable segmentation. <br><br>Hereafter, I report the code used (sorry for the long list of code lines!! :) ).<br>
The application accepts a list of arguments, precisely :<br>1_size_model 2_amplitude_model 3_sigma_smoothing 4_propagationscale 5 curvaturescale 6_levelset_initialvalue<br>I tried a lot of different argument lists, among them you can try the following one<br>
101 10 1 1 1 10<br><br>I would very appreciate to receive any comment, suggestion to solve the problem.<br><br>Thank u in advance,<br><br>Silvano<br><br><br>#include &lt;itkIndex.h&gt;<br>#include &lt;itkImage.h&gt;<br>#include &lt;itkImageFileWriter.h&gt;<br>
#include &lt;itkCastImageFilter.h&gt;<br>#include &lt;itkTimeProbesCollectorBase.h&gt;<br>#include &lt;itkGradientAnisotropicDiffusionImageFilter.h&gt;<br>#include &lt;itkFastMarchingImageFilter.h&gt;<br>#include &lt;itkShapeDetectionLevelSetImageFilter.h&gt;<br>
#include &lt;itkGradientMagnitudeRecursiveGaussianImageFilter.h&gt;<br>#include &lt;itkBoundedReciprocalImageFilter.h&gt;<br><br>typedef itk::Image&lt;float,2&gt; TImage;<br><br>TImage::Pointer model2D_flat( float sizeM, float amp )<br>
{<br>    TImage::Pointer model = TImage::New();<br>   <br>    int hsize = (int)((sizeM-1.0)/2.0);<br>        <br>    std::cout &lt;&lt; &quot;size model image = &quot; &lt;&lt; sizeM;<br>    std::cout &lt;&lt; &quot;, half size model image = &quot; &lt;&lt; hsize &lt;&lt; std::endl;<br>
    <br>    TImage::IndexType start;<br>    start[0] =   0;  <br>    start[1] =   0;  <br><br>    TImage::SizeType  size;<br>    size[0]  = sizeM;<br>    size[1]  = sizeM;<br>    <br>    TImage::RegionType region;<br>    region.SetSize( size );<br>
    region.SetIndex( start );<br>    <br>    model-&gt;SetRegions( region );<br>    model-&gt;Allocate();<br>    <br>    float radius2 = static_cast&lt;float&gt;(sizeM)/4.0;<br>    radius2 = radius2 * radius2;<br>    for ( int y=-hsize; y &lt;= hsize; ++y )<br>
    {<br>        for ( int x=-hsize; x &lt;= hsize; ++x )<br>        {<br>            TImage::IndexType index;<br>            index[0] = (x+hsize);<br>            index[1] = (y+hsize);<br>            if ( (x*x+y*y) &lt; radius2 )<br>
                model-&gt;SetPixel( index, amp );<br>            else<br>                model-&gt;SetPixel( index, amp/2.0 );<br>        }<br>    }<br>    <br>    return model;<br>}<br><br><br>int main(int argc, char **argv)<br>
{<br>    double sizeM = atof( argv[1] );<br>    double amplitude = atof( argv[2] );<br>    double sigma = atof( argv[3] );<br>    double propscale = atof( argv[4] );<br>    double curvscale = atof( argv[5] );<br>    double isovalue = atof( argv[6] );<br>
    <br>    std::cout &lt;&lt; &quot;size= &quot; &lt;&lt; sizeM &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;amplitude= &quot; &lt;&lt; amplitude &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;sigma= &quot; &lt;&lt; sigma &lt;&lt; std::endl;<br>
    std::cout &lt;&lt; &quot;propscale= &quot; &lt;&lt; propscale &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;curvscale= &quot; &lt;&lt; curvscale &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;isovalue= &quot; &lt;&lt; isovalue &lt;&lt; std::endl;<br>
    <br>    TImage::Pointer model = model2D_flat( sizeM, amplitude );<br>    <br>    itk::TimeProbesCollectorBase timeCollector;<br>    timeCollector.Start(&quot;Total&quot;);<br>    <br>    typedef itk::GradientMagnitudeRecursiveGaussianImageFilter&lt; TImage, TImage &gt; GradientFilterType;<br>
    GradientFilterType::Pointer gradient = GradientFilterType::New();<br>    gradient-&gt;SetSigma( sigma );<br>    gradient-&gt;SetNormalizeAcrossScale(false);<br>    <br>    typedef itk::BoundedReciprocalImageFilter&lt; TImage, TImage &gt; BoundFilterType;<br>
    BoundFilterType::Pointer bounder = BoundFilterType::New();<br>    <br>    typedef itk::FastMarchingImageFilter&lt; TImage, TImage &gt;    FastMarchingFilterType;<br>    FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();<br>
    <br>    typedef  itk::ShapeDetectionLevelSetImageFilter&lt; TImage, TImage &gt; ShapeDetectionFilterType;<br>    ShapeDetectionFilterType::Pointer shapeDetection = ShapeDetectionFilterType::New();<br>    <br>    gradient-&gt;SetInput( model );<br>
    bounder-&gt;SetInput( gradient-&gt;GetOutput() );<br>    shapeDetection-&gt;SetInput( fastMarching-&gt;GetOutput() );<br>    shapeDetection-&gt;SetFeatureImage( bounder-&gt;GetOutput() );<br>    <br>    typedef FastMarchingFilterType::NodeContainer        NodeContainer;<br>
    typedef FastMarchingFilterType::NodeType             NodeType;<br>    NodeContainer::Pointer seeds = NodeContainer::New();<br><br>    NodeType node;<br>    const double seedValue = -isovalue;<br>    <br><br>    itk::Index&lt;2&gt; pos; <br>
    int hsize = (int)((sizeM-1.0)/2.0);<br>    pos[0] = hsize; pos[1] = hsize;<br>    node.SetValue( seedValue );<br>    node.SetIndex( pos );<br><br>    seeds-&gt;Initialize();<br>    seeds-&gt;InsertElement( 0, node );<br>
<br>    fastMarching-&gt;SetTrialPoints( seeds );<br>    fastMarching-&gt;SetOutputSize( model-&gt;GetLargestPossibleRegion().GetSize() );<br>    fastMarching-&gt;SetOutputSpacing( model-&gt;GetSpacing() );<br>    fastMarching-&gt;SetOutputOrigin ( model-&gt;GetOrigin() );<br>
    fastMarching-&gt;SetSpeedConstant( 1.0 );<br>    <br>    shapeDetection-&gt;SetPropagationScaling( propscale );<br>    shapeDetection-&gt;SetCurvatureScaling( curvscale );<br>    shapeDetection-&gt;SetMaximumRMSError( 0.02 );<br>
    shapeDetection-&gt;SetNumberOfIterations( 1000 );<br><br>    typedef itk::ImageFileWriter&lt;TImage&gt; WriterType;<br>    WriterType::Pointer iwriter = WriterType::New();<br><br>    timeCollector.Start(&quot;process&quot;);<br>
    iwriter-&gt;SetInput( model );<br>    iwriter-&gt;SetFileName( &quot;model.nii&quot; );<br>    iwriter-&gt;Update();<br>    <br>    iwriter-&gt;SetInput( fastMarching-&gt;GetOutput() );<br>    iwriter-&gt;SetFileName( &quot;fastMarchOutput.nii&quot; );<br>
    iwriter-&gt;Update();<br>    <br>    iwriter-&gt;SetInput( shapeDetection-&gt;GetOutput() );<br>    iwriter-&gt;SetFileName( &quot;shapeOutput.nii&quot; );<br>    iwriter-&gt;Update();<br>    <br>    iwriter-&gt;SetInput( bounder-&gt;GetOutput() );<br>
    iwriter-&gt;SetFileName( &quot;edge.nii&quot; );<br>    iwriter-&gt;Update();<br>    <br>    timeCollector.Stop(&quot;process&quot;);<br>    <br>    std::cout &lt;&lt; &quot;No. elpased iterations: &quot; &lt;&lt; shapeDetection-&gt;GetElapsedIterations() &lt;&lt; std::endl;<br>
    std::cout &lt;&lt; &quot;RMS change: &quot; &lt;&lt; shapeDetection-&gt;GetRMSChange() &lt;&lt; std::endl;<br><br>    timeCollector.Stop(&quot;Total&quot;);<br>    std::cout &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;Computing Time (sec): &quot; &lt;&lt; std::endl;<br>
    timeCollector.Report();<br>}<br><br><br>