[Insight-users] help with GradientVectorFlowImageFilter
Kun
kun_ch at 163.com
Fri Feb 27 12:04:05 EST 2009
Hi, all
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:
===========================================================
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <itkImage.h>
#include <itkGradientRecursiveGaussianImageFilter.h>
#include <itkImageRegionIteratorWithIndex.h>
#include <itkCovariantVector.h>
#include <itkGradientImageFilter.h>
#include <itkGradientToMagnitudeImageFilter.h>
#include <itkDerivativeImageFilter.h>
#include <itkGradientVectorFlowImageFilter.h>
#include <itkLaplacianImageFilter.h>
#include "itkRecursiveGaussianImageFilter.h"
#include "itkImageFileWriter.h"
int main(int argc, char **argv)/**[])*/
{
// Define the dimension of the images
const unsigned int myDimension = 3;
// Declare gradient type
typedef itk::CovariantVector<double, myDimension> myGradientType;
// Declare the types of the images
typedef itk::Image<double, myDimension> myImageType;
typedef itk::Image<myGradientType, myDimension> myGradientImageType;
// Declare the type of the index to access images
typedef itk::Index<myDimension> myIndexType;
// Declare the type of the size
typedef itk::Size<myDimension> mySizeType;
// Declare the type of the Region
typedef itk::ImageRegion<myDimension> myRegionType;
typedef itk::RecursiveGaussianImageFilter<myImageType,myImageType> RecursiveGaussianImageFilterType;
typedef itk::LaplacianImageFilter<myImageType, myImageType> myLaplacianFilterType;
typedef itk::GradientVectorFlowImageFilter<myGradientImageType, myGradientImageType>
myGVFFilterType;
typedef itk::GradientImageFilter<myImageType, double, double>
myGFilterType;
typedef itk::GradientToMagnitudeImageFilter<myGradientImageType, myImageType>
myGToMFilterType;
// Create the image
myImageType::Pointer inputImage = myImageType::New();
// Define their size, and start index
mySizeType size;
size[0] = 64;
size[1] = 64;
size[2] = 64;
myIndexType start;
start.Fill(0);
myRegionType region;
region.SetIndex( start );
region.SetSize( size );
// Initialize Image A
inputImage->SetLargestPossibleRegion( region );
inputImage->SetBufferedRegion( region );
inputImage->SetRequestedRegion( region );
inputImage->Allocate();
// Declare Iterator types apropriated for each image
typedef itk::ImageRegionIteratorWithIndex<myImageType> myIteratorType;
// Create one iterator for the Input Image A (this is a light object)
myIteratorType it( inputImage, inputImage->GetRequestedRegion() );
// Initialize the content of Image A
std::cout << "Input Image initialization " << std::endl;
it.GoToBegin();
while( !it.IsAtEnd() )
{
it.Set( 0.0 );
++it;
}
size[0] = 32;
size[1] = 32;
size[2] = 32;
start[0] = 15;
start[1] = 15;
start[2] = 15;
// Create one iterator for an internal region
region.SetSize( size );
region.SetIndex( start );
myIteratorType itb( inputImage, region );
itb.GoToBegin();
// Initialize the content the internal region
while( !itb.IsAtEnd() )
{
itb.Set( 100.0 );
++itb;
}
myGFilterType::Pointer f_Gradient = myGFilterType::New();
f_Gradient->SetInput(inputImage);
f_Gradient->Update();
typedef itk::ImageFileWriter<myGradientImageType> VectorImageWriterType;
VectorImageWriterType::Pointer GradientWriter = VectorImageWriterType::New();
GradientWriter->SetInput(f_Gradient->GetOutput());
GradientWriter->SetFileName("Gradient.mha");
GradientWriter->Update();
myLaplacianFilterType::Pointer m_LFilter = myLaplacianFilterType::New();
myGVFFilterType::Pointer m_GVFFilter = myGVFFilterType::New();
m_GVFFilter->SetInput(f_Gradient->GetOutput());
m_GVFFilter->SetLaplacianFilter(m_LFilter);
m_GVFFilter->SetNoiseLevel(100);
m_GVFFilter->SetTimeStep(0.002);
m_GVFFilter->SetIterationNum(2);
m_GVFFilter->Update();
myGradientImageType::Pointer m_GVF = m_GVFFilter->GetOutput();
VectorImageWriterType::Pointer writer2 = VectorImageWriterType::New();
writer2->SetInput(m_GVF);
writer2->SetFileName("GGVF.mha");
writer2->Update();
return EXIT_SUCCESS;
}
===========================================================
It seems that the GVF results is the same as the gradient filter. The grdient information is not diffused at all.
Is there any errors when I use the GVF filter?
Thanks all.
Kun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090228/d1bfa302/attachment.htm>
More information about the Insight-users
mailing list