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

**URL:** https://discourse.itk.org/t/use-sitk-cast-function-to-convert-image-resulted-in-crashed/2222
**Category:** Engineering
**Tags:** simpleitk
**Created:** [September 5, 2019, 3:09am UTC](https://discourse.itk.org/t/use-sitk-cast-function-to-convert-image-resulted-in-crashed/2222 "2019-09-05T03:09:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![TechLee](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/d78d45/32.png) [@TechLee](https://discourse.itk.org/u/TechLee)
#### Post date: [September 5, 2019, 3:09am UTC](https://discourse.itk.org/t/use-sitk-cast-function-to-convert-image-resulted-in-crashed/2222/1 "2019-09-05T03:09:00Z")

</div>

```auto
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

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 7, 2019, 11:35am UTC](https://discourse.itk.org/t/use-sitk-cast-function-to-convert-image-resulted-in-crashed/2222/2 "2019-09-07T11:35:56Z")

</div>

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?
