[Insight-users] simple ITK App keeps crashing - what do I do wrong?

Luis Ibanez luis.ibanez at kitware.com
Fri May 12 09:47:26 EDT 2006


Hi Henning,

What is wrong with your getImage() function:

FilterImageType::Pointer getImage(void) {

  RandomImageSourceType::Pointer ris =
              RandomImageSourceType::New();

	return ris->GetOutput();
}


is that you are missing to call the  "Update()"
method in the "ris" filter. The output of the
filter does not exist until you call the Update()
method.


Please read the ITK Software Guide

    http://www.itk.org/ItkSoftwareGuide.pdf


and get familiar with the concepts of smartpointers
and the pipeline architecture, as explained in the
sections "Data Representation" and "Filtering".


   Regards,



      Luis



---------------------
Henning Meyer wrote:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> #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;
> }
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users




More information about the Insight-users mailing list