<div>Hi, all<br><br>I am trying to use GradientVectorFlowImageFilter to diffuse the gradient information to the whole image. The example code works well, but when I change the code, to diffuse the gradient as follows:<br><br>===========================================================<br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br>#include <itkImage.h><br>#include <itkGradientRecursiveGaussianImageFilter.h><br>#include <itkImageRegionIteratorWithIndex.h><br>#include <itkCovariantVector.h><br>#include <itkGradientImageFilter.h><br>#include <itkGradientToMagnitudeImageFilter.h><br>#include <itkDerivativeImageFilter.h><br>#include <itkGradientVectorFlowImageFilter.h><br>#include <itkLaplacianImageFilter.h><br><br>#include "itkRecursiveGaussianImageFilter.h"<br><br>#include "itkImageFileWriter.h"<br><br>int main(int argc, char **argv)/**[])*/ <br>{<br> // Define the dimension of the images<br> const unsigned int myDimension = 3;<br><br> // Declare gradient type<br> typedef itk::CovariantVector<double, myDimension> myGradientType;<br><br> // Declare the types of the images<br> typedef itk::Image<double, myDimension> myImageType;<br> typedef itk::Image<myGradientType, myDimension> myGradientImageType;<br><br> // Declare the type of the index to access images<br> typedef itk::Index<myDimension> myIndexType;<br><br> // Declare the type of the size <br> typedef itk::Size<myDimension> mySizeType;<br><br> // Declare the type of the Region<br> typedef itk::ImageRegion<myDimension> myRegionType;<br><br> typedef itk::RecursiveGaussianImageFilter<myImageType,myImageType> RecursiveGaussianImageFilterType;<br><br> typedef itk::LaplacianImageFilter<myImageType, myImageType> myLaplacianFilterType;<br> typedef itk::GradientVectorFlowImageFilter<myGradientImageType, myGradientImageType><br> myGVFFilterType;<br><br> typedef itk::GradientImageFilter<myImageType, double, double><br> myGFilterType;<br><br> typedef itk::GradientToMagnitudeImageFilter<myGradientImageType, myImageType><br> myGToMFilterType;<br> // Create the image<br> myImageType::Pointer inputImage = myImageType::New();<br><br> // Define their size, and start index<br> mySizeType size;<br> size[0] = 64;<br> size[1] = 64;<br> size[2] = 64; <br><br> myIndexType start;<br> start.Fill(0);<br><br> myRegionType region;<br> region.SetIndex( start );<br> region.SetSize( size );<br><br> // Initialize Image A<br> inputImage->SetLargestPossibleRegion( region );<br> inputImage->SetBufferedRegion( region );<br> inputImage->SetRequestedRegion( region );<br> inputImage->Allocate();<br><br> // Declare Iterator types apropriated for each image <br> typedef itk::ImageRegionIteratorWithIndex<myImageType> myIteratorType;<br><br> // Create one iterator for the Input Image A (this is a light object)<br> myIteratorType it( inputImage, inputImage->GetRequestedRegion() );<br><br> // Initialize the content of Image A<br> std::cout << "Input Image initialization " << std::endl;<br> <br> it.GoToBegin();<br> while( !it.IsAtEnd() ) <br> {<br> it.Set( 0.0 );<br> ++it;<br> }<br><br> size[0] = 32;<br> size[1] = 32;<br> size[2] = 32; <br><br> start[0] = 15;<br> start[1] = 15;<br> start[2] = 15;<br> // Create one iterator for an internal region<br> region.SetSize( size );<br> region.SetIndex( start );<br> myIteratorType itb( inputImage, region );<br> <br> itb.GoToBegin();<br> // Initialize the content the internal region<br> while( !itb.IsAtEnd() ) <br> {<br> itb.Set( 100.0 );<br> ++itb;<br> }<br> <br> myGFilterType::Pointer f_Gradient = myGFilterType::New();<br> f_Gradient->SetInput(inputImage);<br> f_Gradient->Update();<br> typedef itk::ImageFileWriter<myGradientImageType> VectorImageWriterType;<br> VectorImageWriterType::Pointer GradientWriter = VectorImageWriterType::New();<br> GradientWriter->SetInput(f_Gradient->GetOutput());<br> GradientWriter->SetFileName("Gradient.mha");<br> GradientWriter->Update();<br><br> myLaplacianFilterType::Pointer m_LFilter = myLaplacianFilterType::New();<br> myGVFFilterType::Pointer m_GVFFilter = myGVFFilterType::New();<br><br> m_GVFFilter->SetInput(f_Gradient->GetOutput());<br> m_GVFFilter->SetLaplacianFilter(m_LFilter);<br> m_GVFFilter->SetNoiseLevel(100);<br> m_GVFFilter->SetTimeStep(0.002);<br> m_GVFFilter->SetIterationNum(2);<br><br> m_GVFFilter->Update();<br><br> myGradientImageType::Pointer m_GVF = m_GVFFilter->GetOutput();<br> VectorImageWriterType::Pointer writer2 = VectorImageWriterType::New();<br> writer2->SetInput(m_GVF);<br> writer2->SetFileName("GGVF.mha");<br> writer2->Update();<br><br> return EXIT_SUCCESS;<br><br>}<br>===========================================================<br><br>It seems that the GVF results is the same as the gradient filter. The grdient information is not diffused at all. <br><br>Is there any errors when I use the GVF filter?<br><br>Thanks all.<br><br>Kun<br> <br><br></div><br><!-- footer --><br><span title="neteasefooter"/><hr/>
<a href="http://www.yeah.net">网易邮箱,中国第一大电子邮件服务商</a>
</span>