<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.28">
<TITLE>Debug error with Fast marching filter! again</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi all,<BR>
<BR>
I've posted a previous mail on the debug error when doing 3d segmentation using fast marching. I am posting the code here. Can anyone tell me what has gone wrong? I suspect its the way i am providing the 3d coordinates in the command line...need some help here as i've been figuring this for days! Thanks.<BR>
<BR>
i am using the following command line inputs:<BR>
fastmarchingimagefilter "MRI2edit.hdr" "FastMarchingOP.hdr" 140 122 0.5 -0.5 4 420 420 72<BR>
<BR>
so my coordinates are (140,122,72) and my sigma is 0.5, alpha=-0.5, beta=4, timethreshold & stopping value =420.<BR>
<BR>
rgds,<BR>
Zheying<BR>
<BR>
code attached:<BR>
<BR>
<BR>
<BR>
#if defined(_MSC_VER)<BR>
#pragma warning ( disable : 4786 )<BR>
#endif<BR>
<BR>
#ifdef __BORLANDC__<BR>
#define ITK_LEAN_AND_MEAN<BR>
#endif<BR>
<BR>
<BR>
<BR>
#include "itkCurvatureAnisotropicDiffusionImageFilter.h"<BR>
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"<BR>
#include "itkSigmoidImageFilter.h"<BR>
#include "itkImage.h"<BR>
#include "itkFastMarchingImageFilter.h"<BR>
#include "itkBinaryThresholdImageFilter.h"<BR>
#include "itkImageFileReader.h"<BR>
#include "itkImageFileWriter.h"<BR>
#include "itkRescaleIntensityImageFilter.h"<BR>
<BR>
<BR>
int main( int argc, char *argv[] )<BR>
{<BR>
if( argc < 11 )<BR>
{<BR>
std::cerr << "Missing Parameters " << std::endl;<BR>
std::cerr << "Usage: " << argv[0];<BR>
std::cerr << " inputImage outputImage seedX seedY";<BR>
std::cerr << " Sigma SigmoidAlpha SigmoidBeta TimeThreshold StoppingValue seedZ" << std::endl;<BR>
return 1;<BR>
}<BR>
<BR>
<BR>
typedef float InternalPixelType;<BR>
const unsigned int Dimension = 3;<BR>
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<BR>
<BR>
<BR>
<BR>
typedef unsigned char OutputPixelType;<BR>
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<BR>
<BR>
typedef itk::BinaryThresholdImageFilter< InternalImageType,<BR>
OutputImageType > ThresholdingFilterType;<BR>
ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();<BR>
<BR>
const InternalPixelType timeThreshold = atof( argv[8] );<BR>
<BR>
thresholder->SetLowerThreshold( 0.0 );<BR>
thresholder->SetUpperThreshold( timeThreshold );<BR>
<BR>
thresholder->SetOutsideValue( 0 );<BR>
thresholder->SetInsideValue( 255 );<BR>
<BR>
typedef itk::ImageFileReader< InternalImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<BR>
<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
WriterType::Pointer writer = WriterType::New();<BR>
<BR>
reader->SetFileName( argv[1] );<BR>
writer->SetFileName( argv[2] );<BR>
<BR>
typedef itk::RescaleIntensityImageFilter<<BR>
InternalImageType,<BR>
OutputImageType > CastFilterType;<BR>
<BR>
typedef itk::CurvatureAnisotropicDiffusionImageFilter<<BR>
InternalImageType,<BR>
InternalImageType> SmoothingFilterType;<BR>
<BR>
SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();<BR>
<BR>
typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<<BR>
InternalImageType,<BR>
InternalImageType> GradientFilterType;<BR>
<BR>
typedef itk::SigmoidImageFilter< <BR>
InternalImageType,<BR>
InternalImageType> SigmoidFilterType;<BR>
<BR>
GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();<BR>
SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();<BR>
<BR>
sigmoid->SetOutputMinimum( 0.0 );<BR>
sigmoid->SetOutputMaximum( 1.0 );<BR>
<BR>
typedef itk::FastMarchingImageFilter< InternalImageType,<BR>
InternalImageType > FastMarchingFilterType;<BR>
<BR>
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();<BR>
<BR>
smoothing->SetInput( reader->GetOutput() );<BR>
gradientMagnitude->SetInput( smoothing->GetOutput() );<BR>
sigmoid->SetInput( gradientMagnitude->GetOutput() );<BR>
fastMarching->SetInput( sigmoid->GetOutput() );<BR>
thresholder->SetInput( fastMarching->GetOutput() );<BR>
writer->SetInput( thresholder->GetOutput() );<BR>
<BR>
smoothing->SetTimeStep( 0.0625 );<BR>
smoothing->SetNumberOfIterations( 1 );<BR>
smoothing->SetConductanceParameter( 9.0 );<BR>
<BR>
<BR>
const double sigma = atof( argv[5] );<BR>
<BR>
gradientMagnitude->SetSigma( sigma );<BR>
<BR>
<BR>
const double alpha = atof( argv[6] );<BR>
const double beta = atof( argv[7] );<BR>
<BR>
sigmoid->SetAlpha( alpha );<BR>
sigmoid->SetBeta( beta );<BR>
<BR>
typedef FastMarchingFilterType::NodeContainer NodeContainer;<BR>
typedef FastMarchingFilterType::NodeType NodeType;<BR>
NodeContainer::Pointer seeds = NodeContainer::New();<BR>
<BR>
<BR>
InternalImageType::IndexType seedPosition;<BR>
<BR>
seedPosition[0] = atoi( argv[3] );<BR>
seedPosition[1] = atoi( argv[4] );<BR>
seedPosition[2] = atoi( argv[10] );<BR>
<BR>
NodeType node;<BR>
const double seedValue = 0.0;<BR>
<BR>
node.SetValue( seedValue );<BR>
node.SetIndex( seedPosition );<BR>
<BR>
seeds->Initialize();<BR>
seeds->InsertElement( 0, node );<BR>
<BR>
fastMarching->SetTrialPoints( seeds );<BR>
<BR>
CastFilterType::Pointer caster1 = CastFilterType::New();<BR>
CastFilterType::Pointer caster2 = CastFilterType::New();<BR>
CastFilterType::Pointer caster3 = CastFilterType::New();<BR>
CastFilterType::Pointer caster4 = CastFilterType::New();<BR>
<BR>
WriterType::Pointer writer1 = WriterType::New();<BR>
WriterType::Pointer writer2 = WriterType::New();<BR>
WriterType::Pointer writer3 = WriterType::New();<BR>
WriterType::Pointer writer4 = WriterType::New();<BR>
<BR>
caster1->SetInput( smoothing->GetOutput() );<BR>
writer1->SetInput( caster1->GetOutput() );<BR>
writer1->SetFileName("FastMarchingFilterOutput1.png");<BR>
caster1->SetOutputMinimum( 0 );<BR>
caster1->SetOutputMaximum( 255 );<BR>
writer1->Update();<BR>
<BR>
caster2->SetInput( gradientMagnitude->GetOutput() );<BR>
writer2->SetInput( caster2->GetOutput() );<BR>
writer2->SetFileName("FastMarchingFilterOutput2.png");<BR>
caster2->SetOutputMinimum( 0 );<BR>
caster2->SetOutputMaximum( 255 );<BR>
writer2->Update();<BR>
<BR>
caster3->SetInput( sigmoid->GetOutput() );<BR>
writer3->SetInput( caster3->GetOutput() );<BR>
writer3->SetFileName("FastMarchingFilterOutput3.png");<BR>
caster3->SetOutputMinimum( 0 );<BR>
caster3->SetOutputMaximum( 255 );<BR>
writer3->Update();<BR>
<BR>
caster4->SetInput( fastMarching->GetOutput() );<BR>
writer4->SetInput( caster4->GetOutput() );<BR>
writer4->SetFileName("FastMarchingFilterOutput4.png");<BR>
caster4->SetOutputMinimum( 0 );<BR>
caster4->SetOutputMaximum( 255 );<BR>
<BR>
// Software Guide : BeginCodeSnippet<BR>
fastMarching->SetOutputSize(<BR>
reader->GetOutput()->GetBufferedRegion().GetSize() );<BR>
// Software Guide : EndCodeSnippet<BR>
<BR>
<BR>
const double stoppingTime = atof( argv[9] );<BR>
<BR>
// Software Guide : BeginCodeSnippet<BR>
fastMarching->SetStoppingValue( stoppingTime );<BR>
// Software Guide : EndCodeSnippet<BR>
<BR>
<BR>
// Software Guide : BeginCodeSnippet<BR>
try<BR>
{<BR>
writer->Update();<BR>
}<BR>
catch( itk::ExceptionObject & excep )<BR>
{<BR>
std::cerr << "Exception caught !" << std::endl;<BR>
std::cerr << excep << std::endl;<BR>
}<BR>
// Software Guide : EndCodeSnippet<BR>
<BR>
<BR>
writer4->Update();<BR>
<BR>
typedef itk::ImageFileWriter< InternalImageType > InternalWriterType;<BR>
<BR>
InternalWriterType::Pointer mapWriter = InternalWriterType::New();<BR>
mapWriter->SetInput( fastMarching->GetOutput() );<BR>
mapWriter->SetFileName("FastMarchingFilterOutput4.mha");<BR>
mapWriter->Update();<BR>
<BR>
InternalWriterType::Pointer speedWriter = InternalWriterType::New();<BR>
speedWriter->SetInput( sigmoid->GetOutput() );<BR>
speedWriter->SetFileName("FastMarchingFilterOutput3.mha");<BR>
speedWriter->Update();<BR>
<BR>
InternalWriterType::Pointer gradientWriter = InternalWriterType::New();<BR>
gradientWriter->SetInput( gradientMagnitude->GetOutput() );<BR>
gradientWriter->SetFileName("FastMarchingFilterOutput2.mha");<BR>
gradientWriter->Update();<BR>
<BR>
<BR>
return 0;<BR>
}<BR>
<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>