<div dir="ltr">Be sure to build ITK and your example Release and not Debug.<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 11, 2013 at 4:40 AM, zhq <span dir="ltr"><<a href="mailto:15891495523@126.com" target="_blank">15891495523@126.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial"><div><span style="line-height:1.7">Hello , Dear:</span><div style="line-height:1.7;font-size:14px;font-family:arial">
I am learning itkGeodesicActiveContourLevelSetImageFilter , and I can segment a 2 dimension picture . And , now , I am trying to segment a 3 dimension data . But , when I segment a 2 dimension picture , it costs me about one minute . But , it costs me more than 20 minutes to segment a 3 dimension data , the data consists in 4 two-dimensional pictures . Is my code wrong ? </div>
<div><div>#include "itkGeodesicActiveContourLevelSetImageFilter.h"</div><div>#include "itkCurvatureAnisotropicDiffusionImageFilter.h"</div><div>#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"</div>
<div>#include "itkSigmoidImageFilter.h"</div><div>#include "itkFastMarchingImageFilter.h"</div><div>#include "itkRescaleIntensityImageFilter.h"</div><div>#include "itkBinaryThresholdImageFilter.h"</div>
<div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkGDCMImageIO.h"</div><div>#include "itkJPEGImageIO.h"</div><div>#include "itkChangeInformationImageFilter.h"</div>
<div>#include "itkImage.h"</div><div>#include "itkImageSeriesReader.h"</div><div>#include "itkNumericSeriesFileNames.h"</div><div>#include "itkImageFileWriter.h"</div><div>int main()</div>
<div>{</div><div> typedef float InternalPixelType;</div><div> const unsigned int Dimension = 3;</div><div> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;</div><div><br></div>
<div> typedef unsigned char OutputPixelType;</div><div> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;</div><div> typedef itk::BinaryThresholdImageFilter<</div><div>
InternalImageType,</div><div> OutputImageType > ThresholdingFilterType;</div><div><br></div><div> ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();</div>
<div><br></div><div> thresholder->SetLowerThreshold( -80.0 );</div><div> thresholder->SetUpperThreshold( 2 );</div><div><br></div><div> thresholder->SetOutsideValue( 0 );</div><div> thresholder->SetInsideValue( 255 );</div>
<div>// ************* reader ****************************** //</div><div><br></div><div>// typedef itk::ImageFileReader< InternalImageType > ReaderType;</div><div>// ReaderType::Pointer reader = ReaderType::New();</div>
<div>// reader->SetFileName("C:\\Users\\zhq\\Desktop\\VolumeData.vtk");</div><div>// reader->SetFileName("C:\\Users\\zhq\\Desktop\\BrainProtonDensitySlice.png");</div><div>// reader->SetImageIO(itk::GDCMImageIO::New());</div>
<div>// reader->SetFileName("C:\\Users\\zhq\\Desktop\\data\\SNAP_CR\\E403434298\\E403434298S1901I301.dcm");</div><div>// reader->SetImageIO(itk::JPEGImageIO::New());</div><div>// reader->SetFileName("C:\\Users\\zhq\\Desktop\\data\\picture8\\1.jpeg");</div>
<div>// reader->SetFileName("C:\\Users\\zhq\\Desktop\\\\1.jpg");</div><div><br></div><div> typedef itk::ImageSeriesReader<InternalImageType> ReaderType ;</div><div> ReaderType::Pointer reader = ReaderType::New();</div>
<div> typedef itk::NumericSeriesFileNames NameGeneratorType ; </div><div> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();</div><div><br></div><div> nameGenerator->SetSeriesFormat("C:\\Users\\zhq\\Desktop\\data\\SNAP_CR\\E403434298\\E403434298S1901I%3d.dcm");</div>
<div> nameGenerator->SetStartIndex(301);</div><div> nameGenerator->SetEndIndex(304);</div><div> nameGenerator->SetIncrementIndex(1);</div><div><br></div><div> reader->SetImageIO(itk::GDCMImageIO::New());</div>
<div> reader->SetFileNames(nameGenerator->GetFileNames());</div><div> reader->Update();</div><div> std::cout<<"reader update"<<std::endl;</div><div>// ************* finish reader ********************** // </div>
<div><br></div><div><br></div><div>// ************* writer ******************************* // </div><div> typedef itk::ImageFileWriter< OutputImageType > WriterType;</div><div> WriterType::Pointer writer = WriterType::New();</div>
<div> writer->SetFileName("C:\\Users\\zhq\\Desktop\\ActiveContour.vtk");</div><div><br></div><div><br></div><div>// ************* finish writer ********************** //</div><div><br></div><div> typedef itk::RescaleIntensityImageFilter<</div>
<div> InternalImageType,</div><div> OutputImageType > CastFilterType;</div><div><br></div><div> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<</div>
<div> InternalImageType,</div><div> InternalImageType > GradientFilterType;</div><div> typedef itk::SigmoidImageFilter<</div><div> InternalImageType,</div>
<div> InternalImageType > SigmoidFilterType;</div><div><br></div><div> GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();</div><div><br></div><div> SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();</div>
<div><br></div><div> sigmoid->SetOutputMinimum( 0.0 );</div><div> sigmoid->SetOutputMaximum( 1.0 );</div><div><br></div><div> typedef itk::FastMarchingImageFilter<</div><div> InternalImageType,</div>
<div> InternalImageType > FastMarchingFilterType;</div><div><br></div><div> FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();</div><div><br></div><div> typedef itk::ChangeInformationImageFilter<InternalImageType> ChangeInformationFilterType ; </div>
<div> ChangeInformationFilterType::Pointer changeInformationFilter = ChangeInformationFilterType::New();</div><div> changeInformationFilter->ChangeSpacingOn();</div><div> changeInformationFilter->ChangeOriginOn();</div>
<div> changeInformationFilter->ChangeDirectionOn();</div><div><br></div><div> typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,</div><div> InternalImageType > GeodesicActiveContourFilterType;</div>
<div> GeodesicActiveContourFilterType::Pointer geodesicActiveContour =</div><div> GeodesicActiveContourFilterType::New();</div><div><br></div><div> const double propagationScaling = 0.25;</div>
<div><br></div><div> geodesicActiveContour->SetPropagationScaling( propagationScaling );</div><div> geodesicActiveContour->SetCurvatureScaling( 1 );</div><div> geodesicActiveContour->SetAdvectionScaling( 0.5 );</div>
<div><br></div><div> geodesicActiveContour->SetMaximumRMSError( 0.02 );</div><div> geodesicActiveContour->SetNumberOfIterations( 800 );</div><div><br></div><div><br></div><div> changeInformationFilter->SetInput(reader->GetOutput());</div>
<div> gradientMagnitude->SetInput( changeInformationFilter->GetOutput() );</div><div> sigmoid->SetInput( gradientMagnitude->GetOutput() );</div><div><br></div><div> geodesicActiveContour->SetInput( fastMarching->GetOutput() );</div>
<div> geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );</div><div><br></div><div> thresholder->SetInput( geodesicActiveContour->GetOutput() );</div><div> writer->SetInput( thresholder->GetOutput() );</div>
<div><br></div><div> const double sigma = 0.55 ;</div><div> gradientMagnitude->SetSigma( sigma );</div><div><br></div><div> const double alpha = -0.1;</div><div> const double beta = 100;</div><div><br></div><div>
sigmoid->SetAlpha( alpha );</div><div> sigmoid->SetBeta( beta );</div><div><br></div><div> typedef FastMarchingFilterType::NodeContainer NodeContainer;</div><div> typedef FastMarchingFilterType::NodeType NodeType;</div>
<div><br></div><div> NodeContainer::Pointer seeds = NodeContainer::New();</div><div><br></div><div> InternalImageType::IndexType seedPosition;</div><div><br></div><div> seedPosition[0] = 370;//661 ; //370 ; // 81;</div>
<div> seedPosition[1] = 443;//559 ; //443 ; // 114;</div><div> seedPosition[2] = 1;</div><div><br></div><div> const double initialDistance = 5;</div><div><br></div><div> NodeType node;</div><div><br></div><div> const double seedValue = - initialDistance;</div>
<div><br></div><div> node.SetValue( seedValue );</div><div> node.SetIndex( seedPosition );</div><div><br></div><div> seeds->Initialize();</div><div> seeds->InsertElement( 0, node );</div><div><br></div><div> fastMarching->SetTrialPoints( seeds );</div>
<div><br></div><div> fastMarching->SetSpeedConstant( 1.0 );</div><div><br></div><div> fastMarching->SetOutputSize(</div><div> changeInformationFilter->GetOutput()->GetBufferedRegion().GetSize() );</div>
<div> try</div><div> {</div><div><span style="white-space:pre-wrap">        </span> gradientMagnitude->Update();</div><div><span style="white-space:pre-wrap">        </span> std::cout<<"gradientMagnitude update"<<std::endl;</div>
<div> }</div><div> catch( itk::ExceptionObject & excep )</div><div> {</div><div> std::cerr << "Exception caught !" << std::endl;</div><div> std::cerr << excep << std::endl;</div>
<div> }</div><div><br></div><div> sigmoid->Update();</div><div> std::cout<<"sigmoid update"<<std::endl;</div><div><br></div><div> fastMarching->SetOutputSize(</div><div> reader->GetOutput()->GetBufferedRegion().GetSize() );</div>
<div><br></div><div> fastMarching->Update();</div><div> std::cout<<"fastMarching update"<<std::endl;</div><div> try</div><div> {</div><div><span style="white-space:pre-wrap">        </span> geodesicActiveContour->Update();</div>
<div><span style="white-space:pre-wrap">        </span> std::cout<<"geodesicActiveContour update"<<std::endl;</div><div> }</div><div> catch( itk::ExceptionObject & excep )</div><div> {</div><div> std::cerr << "Exception caught !" << std::endl;</div>
<div> std::cerr << excep << std::endl;</div><div> }</div><div><br></div><div> writer->Update();</div><div> std::cout<<"writer update"<<std::endl;</div><div><br></div><div><br></div>
<div><br></div><div> std::cout << std::endl;</div><div> std::cout << "Max. no. iterations: " << geodesicActiveContour->GetNumberOfIterations() << std::endl;</div><div> std::cout << "Max. RMS error: " << geodesicActiveContour->GetMaximumRMSError() << std::endl;</div>
<div> std::cout << std::endl;</div><div> std::cout << "No. elpased iterations: " << geodesicActiveContour->GetElapsedIterations() << std::endl;</div><div> std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange() << std::endl;</div>
<div><br></div><div> return 0;</div><div>}</div></div><div style="line-height:1.7;font-size:14px;font-family:arial"><br></div><div style="line-height:1.7;font-size:14px;font-family:arial"> </div></div></div><br><br><span title="neteasefooter"><span><div>
<div style="border-top:#cccccc 1px solid;padding:10px 5px;font-size:12px;color:#666;line-height:22px">来自网易手机号码邮箱<a href="http://shouji.163.com" style="color:#0000ff" target="_blank">了解更多</a></div></div>
</span></span><br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</div>