[Insight-users] ThresholdLevelSetSegemntation Filter
mohammed abdel samea
mohammed_abdel_samea at yahoo.com
Fri Mar 11 22:23:16 EST 2011
Dear all,
Actually the code that is shown in this message for you is used for segment a 3D
image based on Threshold Level Set Segmentation Filter, what I did is just copy
this code from
Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx
I did it adjustable for my image. which means: the seed point position I used is
completely inside the ROI, file is the file name of my input image it just 1024
x 1024 x 2 gray scale tif image for testing, aaa.tif is the output image, and
[30, 50] are the lower and upper threshold interval.
typedef float InternalPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::BinaryThresholdImageFilter<InternalImageType, OutputImageType>
ThresholdingFilterType;
ThresholdingFilterType::Pointer thresholder =
ThresholdingFilterType::New();
thresholder->SetLowerThreshold( -1000.0 );
thresholder->SetUpperThreshold( 0.0 );
thresholder->SetOutsideValue( 0 );
thresholder->SetInsideValue( 255 );
typedef itk::ImageFileReader< InternalImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( file );
reader->Update();
writer->SetFileName( "aaa.tif" );
typedef itk::FastMarchingImageFilter< InternalImageType, InternalImageType >
FastMarchingFilterType;
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
const InternalImageType * inputImage = reader->GetOutput();
fastMarching->SetOutputRegion( inputImage->GetBufferedRegion() );
fastMarching->SetOutputSpacing( inputImage->GetSpacing() );
fastMarching->SetOutputOrigin( inputImage->GetOrigin() );
fastMarching->SetOutputDirection( inputImage->GetDirection() );
typedef itk::ThresholdSegmentationLevelSetImageFilter< InternalImageType,
InternalImageType > ThresholdSegmentationLevelSetImageFilterType;
ThresholdSegmentationLevelSetImageFilterType::Pointer thresholdSegmentation =
ThresholdSegmentationLevelSetImageFilterType::New();
thresholdSegmentation->SetPropagationScaling( 1.0 );
thresholdSegmentation->SetCurvatureScaling( 1.0 );
thresholdSegmentation->SetMaximumRMSError( 0.02 );
thresholdSegmentation->SetNumberOfIterations( 1200 );
thresholdSegmentation->SetUpperThreshold( 250 );
thresholdSegmentation->SetLowerThreshold( 30 );
thresholdSegmentation->SetIsoSurfaceValue(0.0);
typedef FastMarchingFilterType::NodeContainer NodeContainer;
typedef FastMarchingFilterType::NodeType NodeType;
NodeContainer::Pointer seeds = NodeContainer::New();
InternalImageType::IndexType seedPosition;
seedPosition[0] = 358;
seedPosition[1] = 529;
seedPosition[2] = 2;
const double initialDistance = 5.0;
NodeType node;
const double seedValue = - initialDistance;
node.SetValue( seedValue );
node.SetIndex( seedPosition );
seeds->Initialize();
seeds->InsertElement( 0, node );
fastMarching->SetTrialPoints( seeds );
fastMarching->SetSpeedConstant( 1.0 );
fastMarching->Update();
thresholdSegmentation->SetInput( fastMarching->GetOutput() );
thresholdSegmentation->SetFeatureImage( reader->GetOutput() );
thresholdSegmentation->Update();
thresholder->SetInput( thresholdSegmentation->GetOutput() );
thresholder->Update();
writer->SetInput( thresholder->GetOutput() );
writer->Update();
Firstly, There is no error messange. However, the output image "aaa.tif" is
black. so I don't have interperation about what's the error. I just want to make
it works. your help is really appericiated about this.
Secondly, the purpose of using Fast Marching segmentation is generate the
initial countor based on the seed point to use it as the countor image (or the
zero level set image) to use it as input to the ThresholdLevelSet Filter. is it
right?. Also, I cann't understand what is the purpose of initialDistance for the
fast marching. I'm sorry I'm not familar with Level Set and ITK documentation is
not enough for me to understand everything.
Thirdly, I know that the purpose of ThresholdLevelSet is find the optimal lower
and upper thresholds for segment the image using Level Set which this filter is
the extension of the Connected Threshold method. is it right?. How is it?.
Best Regards,
Mohammed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110311/6a039b72/attachment.htm>
More information about the Insight-users
mailing list