I’m quite new to C++ and ITK (I have mainly used Python and SimpleITK up until now).
I’m trying to read an image and get some statistics from this image, but only in an ellipse-shaped region.
For this, I am using the SpatialObjectToImageStatisticsCalculator (the code is added below).
However, I always get the following error:
.../Modules/Numerics/Statistics/include/itkMeanSampleFilter.hxx:182: itk::ERROR: MeanSampleFilter(0x7fd1bed06c40): Total frequency was too close to zero: 0 Abort trap: 6
I have taken a look at ‘itkMeanSampleFilter.hxx’ and it seems that the frequency of the iterator stays 0.
But, with my limited knowledge of C++ and ITK, I am not sure what this means or what causes it.
Other things I’ve tried:
I’ve saved the ellipse to an image and checked that it is actually in the correct position (which it is).
I have tried the example in the ‘SpatialObjectToImageStatisticsCalculator.cxx’ file, where a random test image is created (not read from a file), and this works.
I have also tried saving this random test image and then reading it to use with the statistics calculator, but then I get the same error. So, it seems that something goes wrong in reading the file.
Searching online didn’t get me any further.
Can anyone help me understand what I’m doing wrong? Thanks in advance!
This is the code I used:
// Read image typedef float PixelType; const unsigned int Dimension = 3; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageFileReader< ImageType > ReaderType; ReaderType::Pointer reader = ReaderType::New(); const char * InputFilename = argv; reader->SetFileName( InputFilename ); reader->UpdateOutputInformation(); ImageType::Pointer image = reader->GetOutput(); // Create ellipse-shape spatial object itk::FixedArray< int , 3> radius_vx; radius_vx = 21; radius_vx = 21; radius_vx = 3; typedef itk::EllipseSpatialObject<3> EllipseType; EllipseType::Pointer ellipse = EllipseType::New(); ellipse->SetRadius(radius_vx); EllipseType::VectorType offset; ellipse->ComputeObjectToParentTransform(); // Calculate statistics typedef itk::SpatialObjectToImageStatisticsCalculator<ImageType, EllipseType> CalculatorType; CalculatorType::Pointer calculator = CalculatorType::New(); calculator->SetImage(image); calculator->SetSpatialObject(ellipse); calculator->Update(); std::cout << "Sample mean = " << calculator->GetMean() << std::endl; std::cout << "Sample covariance = " << calculator->GetCovarianceMatrix() << std::endl;