use sitk::cast() function to convert image resulted in crashed

sitk::Image fixed;
olderPath[0] = QFileDialog::getExistingDirectory(this, tr("Choose Ref dicom folder"), preFolder,   QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly);

if (folderPath[0].isEmpty()) {
      return;
}

sitk::ImageSeriesReader reader;
const std::vector<std::string> dicom_names =       sitk::ImageSeriesReader::GetGDCMSeriesFileNames(qPrintable(folderPath[0]));
reader.SetFileNames(dicom_names);
fixed = reader.Execute();

qDebug() << fixed.GetPixelIDTypeAsString().data(); // **type is 16-bit signed integer**

 fixed = sitk::Cast(fixed, sitk::sitkFloat32); // **crashed here**

any help would be appreciated

Hello TechLee,

Firstly, what do you mean by “crash”? That is not a technical description for a developer. segmentation fault? Have your tried adding a try...catch block to catch an exception?

Your code looks OK. Most likely it is related to you configuration and build environment. Focus on creating a minimal compilable example to demonstrate your problem, which includes a CMakeLists.txt file and a cxx file. Is the Qt widget really needed?

Also you are using SimpleITK from the C++ interface. How have you compiled SimpleITK? Make options? How is it installed? What OS are you on? Compiler? Version of SimpleITK? etc?

1 Like