[Insight-users] simple ITK App keeps crashing - what do I do wrong?
Henning Meyer
tutmann at gmail.com
Thu May 11 14:42:26 EDT 2006
Hello,
I have problems writing a registration ITK app.
Somehow I don't seem to get the concept of smartpointers. I attached a
small app, which should generates 5 random 3D images and blurr them.
But the application crashes:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I complied it in MSVC 7.1 and ran it under WinXP Professional.
When the images are generated inline in main() instead, then
everything runs fine. But whats wrong with my getImage() function?
Please help me!
I like ITK very much, and I would really like to use it!
Thank you,
Henning
-------------- next part --------------
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkImage.h"
#include "itkTransform.h"
#include "itkResampleImageFilter.h"
#include "itkRecursiveGaussianImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkRandomImageSource.h"
typedef float FilterPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< FilterPixelType, Dimension > FilterImageType;
typedef itk::ResampleImageFilter< FilterImageType, FilterImageType > ResampleFilterType;
typedef itk::Transform< double, Dimension, Dimension> BaseTransformType;
typedef std::vector<std::string> FileNamesContainer;
typedef std::vector< FileNamesContainer > SeriesFilelist;
typedef itk::IdentityTransform< double, Dimension > IdentityTransformType;
typedef itk::RecursiveGaussianImageFilter< FilterImageType, FilterImageType > GaussFilterType;
typedef itk::LinearInterpolateImageFunction< FilterImageType, double > InterpolatorType;
typedef itk::RandomImageSource< FilterImageType > RandomImageSourceType;
const float gaussSigma = 2.0;
FilterImageType::Pointer gaussTransform(const FilterImageType::Pointer sourceImage, FilterImageType::SizeType destSize,
const BaseTransformType *transform, float gaussSigma) {
FilterImageType::SizeType sourceSize = sourceImage->GetBufferedRegion().GetSize();
GaussFilterType::Pointer filterX = GaussFilterType::New();
GaussFilterType::Pointer filterY = GaussFilterType::New();
GaussFilterType::Pointer filterZ = GaussFilterType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
filterX->SetDirection( 0 ); // 0 --> X direction
filterY->SetDirection( 1 ); // 1 --> Y direction
filterZ->SetDirection( 2 ); // 2 --> Z direction
filterX->SetOrder( GaussFilterType::ZeroOrder );
filterY->SetOrder( GaussFilterType::ZeroOrder );
filterZ->SetOrder( GaussFilterType::ZeroOrder );
filterX->SetNormalizeAcrossScale( true );
filterY->SetNormalizeAcrossScale( true );
filterZ->SetNormalizeAcrossScale( true );
filterX->SetSigma( gaussSigma );
filterY->SetSigma( gaussSigma );
filterZ->SetSigma( gaussSigma );
filterX->SetInput( sourceImage );
filterY->SetInput( filterX->GetOutput() );
filterZ->SetInput( filterY->GetOutput() );
resampler->SetInterpolator( interpolator );
resampler->SetTransform( transform );
FilterImageType::SpacingType destSpacing;
for(unsigned int i = 0; i < Dimension; ++i) {
destSpacing[i] = sourceImage->GetSpacing()[i] * (sourceSize[i] / destSize[i]);
}
resampler->SetInput( filterZ->GetOutput() );
resampler->SetSize( destSize );
resampler->SetOutputSpacing( destSpacing );
resampler->SetOutputOrigin( sourceImage->GetOrigin() );
resampler->SetDefaultPixelValue( 0 );
resampler->Update();
return resampler->GetOutput();
}
FilterImageType::Pointer getImage(void) {
RandomImageSourceType::Pointer ris = RandomImageSourceType::New();
return ris->GetOutput();
}
int main( int argc, char* argv[] )
{
FilterImageType::SizeType destSize;
destSize[0] = 100;
destSize[1] = 100;
destSize[2] = 100;
for(int i=0; i < 5; ++i) {
FilterImageType::Pointer image = getImage();
FilterImageType::Pointer filteredImage = gaussTransform(image, destSize, IdentityTransformType::New(), gaussSigma);
}
return EXIT_SUCCESS;
}
More information about the Insight-users
mailing list