Hi there
I’m debugging some code to perform a process on 3D MRI data and I’m getting hung up on a crash I keep encountering when my application is performing a type cast from an unsigned short image to a float.
The relevant snippet of code is as follows:
indent preformatted text by 4 spaces
typedef unsigned short InputPixelType;
typedef float OutputPixelType;
const unsigned int dims = 3;
typedef itk::Image<InputPixelType, dims> InputImageType;
typedef itk::Image<OutputPixelType, dims> OutputImageType;
// Import the image data from pointer
typedef itk::ImportImageFilter<InputPixelType, dims> ImportFilterType;
ImportFilterType::Pointer importFilter = ImportFilterType::New();
// Set up region, spacing, origin, direction etc… (not included to save space)
// m_pSrc is an unsigned short pointer to image data
// m_size is the size (in pixels) of the image dataset
const bool LetImageContainerManageMemory = true;
importFilter->SetImportPointer(m_pSrc,m_size, LetImageContainerManageMemory);
importFilter->Update();
// Now cast the image
typedef itk::CastImageFilter<InputImageType, OutputImageType> CastFilterType;
CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput(importFilter->GetOutput());
castFilter->Update();
indent preformatted text by 4 spaces
Upon calling castFilter->Update(), I get a crash which looks like a segmentation fault type of crash. (in reality, I have the Update() call in a try-catch block); does anyone have any suggestions as to why this may be occurring? Are there extra steps I can take to ensure the cast performs safely?
This may be relevant but this algorithm is being performed in a separate thread; I don’t know how well ITK calls handle being placed into worker threads.
Thank you!