<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi Daniel, </DIV>
<DIV>I have a question. if Update should be called on the last filter in the pipeline why its called after each writer in this example ? I could n't see the purpose ?</DIV>
<DIV>Thanks</DIV>
<DIV>Martine</DIV>
<DIV><BR> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">----- Message d'origine ----<BR>De : Daniel Mace <dlm19@duke.edu><BR>À : Martine Lefevre <martine_lef@yahoo.fr><BR>Cc : insight itk <insight-users@itk.org><BR>Envoyé le : Lundi, 25 Août 2008, 5h59mn 56s<BR>Objet : Re: [Insight-users] meaning of Update() function? where exactly this function should be placed ?<BR><BR>Martine,<BR><BR>You should only need to call Update() on the last filter in the pipeline <BR>(in your case, the writers). As you noted, the Update() on the writer <BR>will trickle down and call Update on all the filters in the pipeline. <BR>It should also be called after you have set all the parameters for all <BR>the filters in the pipeline. In your case, you are calling <BR>writer4->Update() before you have set the parameters for your <BR>FastMarchingFilter (which might be why it keeps running).<BR><BR>The only time I've
needed to call Update() on a filter that is not the <BR>last filter in the pipeline is to Update the reader if I need to get the <BR>size of the image prior to updating the pipeline (which, may or may not <BR>have been resolved by now).<BR><BR>Cheers,<BR>Dan<BR><BR><BR>Martine Lefevre wrote:<BR>><BR>> Dear itk users,<BR>><BR>> I’m new to itk (just in my first week). I have successfully configured <BR>> itk and also vtk. I am now reading the ItkSoftwareGuide and I trying <BR>> to run some of the examples provided. I’m little bit confused with the <BR>> meaning of the Update function (for instance writer->Update(); ). <BR>> According to the book update function triggers the execution of the <BR>> pipeline. When I change its location in the code, the code still <BR>> running without end. For example in the example <BR>> FastMarchingImageFilter.c++ if I move writer4->Update();and put it <BR>> just after
caster4->SetOutputMaximum( 255 ); ,as with the other <BR>> writers, the code still running without end ! <BR>><BR>> I couldn’t understand where exactly this function should be placed in <BR>> a given code.<BR>><BR>> Is it better to call this function with the last filter (i.e. a writer <BR>> ) or I can call it after each filter (and even reader and writer) ? <BR>> What’s the difference between both??<BR>><BR>> Please could you answer me?<BR>><BR>> Thank you<BR>><BR>> Martine<BR>><BR>> Please see the code:<BR>><BR>> <BR>><BR>> // The following example implements a fast marching solution to a <BR>> simple level set evolution problem.<BR>><BR>> #include "itkCurvatureAnisotropicDiffusionImageFilter.h"<BR>><BR>> #include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"<BR>><BR>> #include "itkSigmoidImageFilter.h"<BR>><BR>> #include
"itkImage.h"<BR>><BR>> #include "itkFastMarchingImageFilter.h"<BR>><BR>> #include "itkBinaryThresholdImageFilter.h"<BR>><BR>> #include "itkImageFileReader.h"<BR>><BR>> #include "itkImageFileWriter.h"<BR>><BR>> #include "itkRescaleIntensityImageFilter.h"<BR>><BR>> <BR>><BR>> int main( )<BR>><BR>> {<BR>><BR>> typedef float InternalPixelType;<BR>><BR>> const unsigned int Dimension = 2;<BR>><BR>> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<BR>><BR>> typedef unsigned char OutputPixelType;<BR>><BR>> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<BR>><BR>> typedef itk::BinaryThresholdImageFilter< InternalImageType, <BR>> OutputImageType > ThresholdingFilterType;<BR>><BR>> ThresholdingFilterType::Pointer thresholder = <BR>> ThresholdingFilterType::New();<BR>><BR>> const InternalPixelType
timeThreshold = atof( "100" );<BR>><BR>> thresholder->SetLowerThreshold( 0.0 );<BR>><BR>> thresholder->SetUpperThreshold( timeThreshold );<BR>><BR>> thresholder->SetOutsideValue( 0 );<BR>><BR>> thresholder->SetInsideValue( 255 );<BR>><BR>> typedef itk::ImageFileReader< InternalImageType > ReaderType;<BR>><BR>> typedef itk::ImageFileWriter< OutputImageType > WriterType;<BR>><BR>> ReaderType::Pointer reader = ReaderType::New();<BR>><BR>> WriterType::Pointer writer = WriterType::New();<BR>><BR>> reader->SetFileName("d:/BrainProtonDensitySlice.png");<BR>><BR>> writer->SetFileName("d:/FastMarchingSegmentedImg.png");<BR>><BR>> typedef itk::RescaleIntensityImageFilter< InternalImageType, <BR>> OutputImageType > CastFilterType;<BR>><BR>> typedef itk::CurvatureAnisotropicDiffusionImageFilter< <BR>> InternalImageType, InternalImageType >
SmoothingFilterType;<BR>><BR>> SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();<BR>><BR>> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< <BR>> InternalImageType, InternalImageType > GradientFilterType;<BR>><BR>> typedef itk::SigmoidImageFilter< InternalImageType, InternalImageType <BR>> > SigmoidFilterType;<BR>><BR>> GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();<BR>><BR>> SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();<BR>><BR>> sigmoid->SetOutputMinimum( 0.0 );<BR>><BR>> sigmoid->SetOutputMaximum( 1.0 );<BR>><BR>> typedef itk::FastMarchingImageFilter< InternalImageType, <BR>> InternalImageType > FastMarchingFilterType;<BR>><BR>> FastMarchingFilterType::Pointer fastMarching = <BR>> FastMarchingFilterType::New();<BR>><BR>> smoothing->SetInput( reader->GetOutput()
);<BR>><BR>> gradientMagnitude->SetInput( smoothing->GetOutput() );<BR>><BR>> sigmoid->SetInput( gradientMagnitude->GetOutput() );<BR>><BR>> fastMarching->SetInput( sigmoid->GetOutput() );<BR>><BR>> thresholder->SetInput( fastMarching->GetOutput() );<BR>><BR>> writer->SetInput( thresholder->GetOutput() );<BR>><BR>> smoothing->SetTimeStep( 0.125 );<BR>><BR>> smoothing->SetNumberOfIterations( 5 );<BR>><BR>> smoothing->SetConductanceParameter( 9.0 );<BR>><BR>> const double sigma = atof( "1.0" );<BR>><BR>> gradientMagnitude->SetSigma( sigma );<BR>><BR>> const double alpha = atof( "-0.5" );<BR>><BR>> const double beta = atof( "3.0" );<BR>><BR>> <BR>><BR>> sigmoid->SetAlpha( alpha );<BR>><BR>> sigmoid->SetBeta( beta );<BR>><BR>> typedef FastMarchingFilterType::NodeContainer NodeContainer;<BR>><BR>> typedef
FastMarchingFilterType::NodeType NodeType;<BR>><BR>> NodeContainer::Pointer seeds = NodeContainer::New();<BR>><BR>> InternalImageType::IndexType seedPosition;<BR>><BR>> seedPosition[0] = atoi( "81" );<BR>><BR>> seedPosition[1] = atoi( "114" );<BR>><BR>> NodeType node;<BR>><BR>> const double seedValue = 0.0;<BR>><BR>> node.SetValue( seedValue );<BR>><BR>> node.SetIndex( seedPosition );<BR>><BR>> seeds->Initialize();<BR>><BR>> seeds->InsertElement( 0, node );<BR>><BR>> fastMarching->SetTrialPoints( seeds );<BR>><BR>> CastFilterType::Pointer caster1 = CastFilterType::New();<BR>><BR>> CastFilterType::Pointer caster2 = CastFilterType::New();<BR>><BR>> CastFilterType::Pointer caster3 = CastFilterType::New();<BR>><BR>> CastFilterType::Pointer caster4 = CastFilterType::New();<BR>><BR>> WriterType::Pointer writer1 = WriterType::New();<BR>><BR>>
WriterType::Pointer writer2 = WriterType::New();<BR>><BR>> WriterType::Pointer writer3 = WriterType::New();<BR>><BR>> WriterType::Pointer writer4 = WriterType::New();<BR>><BR>> caster1->SetInput( smoothing->GetOutput() );<BR>><BR>> writer1->SetInput( caster1->GetOutput() );<BR>><BR>> writer1->SetFileName("d:/FastMarchingFilterOutput1.png");<BR>><BR>> caster1->SetOutputMinimum( 0 );<BR>><BR>> caster1->SetOutputMaximum( 255 );<BR>><BR>> writer1->Update();<BR>><BR>> caster2->SetInput( gradientMagnitude->GetOutput() );<BR>><BR>> writer2->SetInput( caster2->GetOutput() );<BR>><BR>> writer2->SetFileName("d:/FastMarchingFilterOutput2.png");<BR>><BR>> caster2->SetOutputMinimum( 0 );<BR>><BR>> caster2->SetOutputMaximum( 255 );<BR>><BR>> writer2->Update();<BR>><BR>> caster3->SetInput( sigmoid->GetOutput()
);<BR>><BR>> writer3->SetInput( caster3->GetOutput() );<BR>><BR>> writer3->SetFileName("d:/FastMarchingFilterOutput3.png");<BR>><BR>> caster3->SetOutputMinimum( 0 );<BR>><BR>> caster3->SetOutputMaximum( 255 );<BR>><BR>> writer3->Update();<BR>><BR>> caster4->SetInput( fastMarching->GetOutput() );<BR>><BR>> writer4->SetInput( caster4->GetOutput() );<BR>><BR>> writer4->SetFileName("d:/FastMarchingFilterOutput4.png");<BR>><BR>> caster4->SetOutputMinimum( 0 );<BR>><BR>> caster4->SetOutputMaximum( 255 );<BR>><BR>> writer4->Update(); // here where I have moved writer4->Update();<BR>><BR>> fastMarching->SetOutputSize( <BR>> reader->GetOutput()->GetBufferedRegion().GetSize() );<BR>><BR>> const double stoppingTime = atof( "100" );<BR>><BR>> fastMarching->SetStoppingValue( stoppingTime );<BR>><BR>>
try<BR>><BR>> {<BR>><BR>> writer->Update();<BR>><BR>> }<BR>><BR>> catch( itk::ExceptionObject & excep )<BR>><BR>> {<BR>><BR>> std::cerr << "Exception caught !" << std::endl;<BR>><BR>> std::cerr << excep << std::endl;<BR>><BR>> }<BR>><BR>> //writer4->Update();<BR>><BR>> typedef itk::ImageFileWriter< InternalImageType > InternalWriterType;<BR>><BR>> InternalWriterType::Pointer mapWriter = InternalWriterType::New();<BR>><BR>> mapWriter->SetInput( fastMarching->GetOutput() );<BR>><BR>> mapWriter->SetFileName("d:/FastMarchingFilterOutput4.mha");<BR>><BR>> mapWriter->Update();<BR>><BR>> InternalWriterType::Pointer speedWriter = InternalWriterType::New();<BR>><BR>> speedWriter->SetInput( sigmoid->GetOutput() );<BR>><BR>> speedWriter->SetFileName("d:/FastMarchingFilterOutput3.mha");<BR>><BR>>
speedWriter->Update();<BR>><BR>> InternalWriterType::Pointer gradientWriter = InternalWriterType::New();<BR>><BR>> gradientWriter->SetInput( gradientMagnitude->GetOutput() );<BR>><BR>> gradientWriter->SetFileName("d:/FastMarchingFilterOutput2.mha");<BR>><BR>> gradientWriter->Update();<BR>><BR>> std::cout << "Code end !" << std::endl;<BR>><BR>> std::cin.get();<BR>><BR>> return 0;<BR>><BR>> }<BR>><BR>><BR>><BR>> ------------------------------------------------------------------------<BR>> Envoyé avec Yahoo! Mail <BR>> <<A href="http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html" target=_blank>http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html</A>>.<BR>> Une boite mail plus
intelligente.<BR>> ------------------------------------------------------------------------<BR>><BR>> _______________________________________________<BR>> Insight-users mailing list<BR>> <A href="mailto:Insight-users@itk.org" ymailto="mailto:Insight-users@itk.org">Insight-users@itk.org</A><BR>> <A href="http://www.itk.org/mailman/listinfo/insight-users" target=_blank>http://www.itk.org/mailman/listinfo/insight-users</A><BR>> <BR><BR></DIV></DIV></div><br>
<hr size="1">
Envoyé avec <a href="http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html">Yahoo! Mail</a>.<br>Une boite mail plus intelligente. </a></body></html>