[Insight-users] Trying to monitor progression of fast march operation

Dan Mueller dan.muel at gmail.com
Fri Apr 24 00:15:05 EDT 2009


Hi Rick,

This filter works for me without issue (see code below and attached
screenshots).

Perhaps you can try the following:

1. Do not set the fast marching output size, as you set the input
2. Set TargetOffset to zero
3. Verify the input to the filter is in the range [0,1]
4. Verify the filter runs as expected when no stop points are set

If all these fail, then perhaps it is an issue with the wrappers?
(though be sure this is your last thought, not the first).

Hope this helps.

Regards, Dan

#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkFastMarchingUpwindGradientImageFilter.h"

int main( int argc, char *argv[] )
{
  const unsigned int Dimension = 2;
  typedef float PixelType;
  typedef itk::Image< PixelType, Dimension > ImageType;
  typedef itk::ImageFileWriter< ImageType > WriterType;
  typedef itk::FastMarchingUpwindGradientImageFilter< ImageType >
FastMarchingType;
  typedef FastMarchingType::NodeContainer NodeContainer;
  typedef FastMarchingType::NodeType NodeType;

  // Create speed image
  ImageType::SizeType size;
  size.Fill( 100 );
  ImageType::RegionType region( size );
  ImageType::Pointer image = ImageType::New();
  image->SetRegions( region );
  image->Allocate();
  image->FillBuffer( 1.0 );

  // Set trial point
  ImageType::IndexType trial1;
  trial1.Fill( 50 );
  NodeType node1;
  node1.SetValue( 0.0 );
  node1.SetIndex( trial1 );
  NodeContainer::Pointer trial = NodeContainer::New();
  trial->Initialize();
  trial->InsertElement( 0, node1 );

  // Set stopping point
  ImageType::IndexType stop1;
  stop1.Fill( 40 );
  NodeType node2;
  node2.SetValue( 0.0 );
  node2.SetIndex( stop1 );
  NodeContainer::Pointer stop = NodeContainer::New();
  stop->Initialize();
  stop->InsertElement( 0, node2 );

  // Create fast marching filter
  FastMarchingType::Pointer filter = FastMarchingType::New();
  filter->SetInput( image );
  filter->SetTrialPoints( trial );
  filter->SetTargetReachedModeToOneTarget();
  filter->SetTargetOffset( 0 ); // Stop immediately
  filter->SetTargetPoints( stop );
  filter->Update();

  // Write output
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( "D:/Temp/FastMarchingStopTest.mha" );
  writer->SetInput( filter->GetOutput() );
  writer->Update();

  return EXIT_SUCCESS;
}

2009/4/22 Rick Giuly <rgiuly at gmail.com>:
> Hello All,
>
> The FastMarchingUpwindGradientImageFilter stopping points don't seem to be
> working for me.
>
> Just to check with you guys that I'm interpreting the output right, here's
> how I'm looking at it:
> I'm looking at the 3D volume that the filter produces assuming that it is
> initialized to a very large value (1.70141e+38) and then where the march has
> happened the values are more on the order of 0.5 or so.
>
> I've tried setting the stopping point to points very close to the seed-point
> (1 pixel away or so) and the march seems to be going far beyond, like 100's
> of pixels beyond. I also tried setting the stopping point to the seed point
> and that gives a result that looks the same (seems like that should cause it
> to terminate almost immediately).
>
> So, I'm not sure what's going on.
>
> Here are the parts of my code that deal with the filter. I'm also attaching
> the file with the complete code.
>
>     FastMarchingFilterType = itk.FastMarchingUpwindGradientImageFilter[
> InternalImageType,
>                               InternalImageType ]
>
>   NodeType = itk.LevelSetNode[InternalPixelType, Dimension]
>   NodeContainer = itk.VectorContainer[itk.UI, NodeType]
>
>   numpyStopPointList = [array(seedPosition) + array([1,0,0])]
>   print numpyStopPointList
>     stopPoints = NodeContainer.New()
>   for numpyPoint in numpyStopPointList:
>       stopPointNode = NodeType()
>       stopPointNode.SetValue(0)
>       stopPointNode.SetIndex(numpyPoint)
>       stopPoints.InsertElement(0, stopPointNode)
>     fastMarching = FastMarchingFilterType.New()
>   fastMarching.SetTargetReachedModeToOneTarget()
>   fastMarching.SetTargetPoints(stopPoints)
>
>     seeds = NodeContainer.New()
>         node = NodeType()
>   seedValue = 0.0
>     node.SetValue( seedValue )
>   node.SetIndex( seedPosition )
>   print "fastmarch seed position", seedPosition
>     seeds.Initialize();
>   seeds.InsertElement( 0, node )
>     fastMarching.SetTrialPoints(  seeds  );
>       fastMarching.SetOutputSize(
>           reader.GetOutput().GetBufferedRegion().GetSize() )
>
>
> Dan Mueller wrote:
>>
>> Hi Rick,
>>
>> You may want to investigate FastMarchingUpwindGradientImageFilter:
>>
>>  http://www.itk.org/Doxygen/html/classitk_1_1FastMarchingUpwindGradientImageFilter.html
>>
>> This is a subclass of the normal fast marching filter which allows you
>> to set the "target reached mode". By default all of the gradient
>> "stuff" is turned off, so you can treat the filter as you would the
>> parent class. For example, just add these lines:
>>    filter->SetTargetReachedModeToAllTargets(); // Other options exist also
>>    filter->SetTargetPoints( targetPoints ); // You need to create these
>>
>> (An aside: it is a shame this functionality was added to the subclass,
>> not the parent filter.)
>>
>> Hope this helps.
>>
>> Cheers, Dan
>>
>> 2009/4/14 Rick Giuly <rgiuly at gmail.com>:
>>
>>>
>>> Hello All,
>>>
>>> I'm trying to monitor progression of fast march operation so I can stop
>>> it
>>> when it has spread to a certain volume. I figured that AddObserver might
>>> be
>>> a way to do this... but it seems that the callback is not called. Is
>>> there
>>> some other way to monitor the fast march progression?
>>>
>>>
>>> Here is the test that I used (in python):
>>>
>>> fastMarching = FastMarchingFilterType.New()
>>>
>>> iterationCommand = itk.PyCommand.New()
>>> iterationCommand.SetCommandCallable(fastMarchIterationUpdate)
>>> fastMarching.AddObserver(itk.IterationEvent(),
>>> iterationCommand.GetPointer())
>>>
>>>
>>>
>>> -rick
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FastMarchingTest-NoStopping.png
Type: image/png
Size: 15029 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090424/b1505b74/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FastMarchingTest-Stopping.png
Type: image/png
Size: 3979 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090424/b1505b74/attachment-0003.png>


More information about the Insight-users mailing list