Page MenuHomePhabricator

SAM tool: Custom NRRD writer not working as expected in Ubuntu
Closed, ResolvedPublic

Description

For faster write speeds in SAM tool, we wrote a custom function instead of using mitk::IOUtil::Save function.
The function:

template <typename TPixel, unsigned int VImageDimension>
void mitk::SegmentAnythingPythonService::ITKWriter(const itk::Image<TPixel, VImageDimension> *image, std::string& outputFilename)
{
  typedef itk::Image<TPixel, VImageDimension> ImageType;
  typedef itk::ImageFileWriter<ImageType> WriterType;
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(image);
  try
  {
    writer->Update();
  }
  catch (const itk::ExceptionObject &error)
  {
    MITK_ERROR << "Error: " << error << std::endl;
    mitkThrow() << "Error: " << error;
  }
}

However, the NRRD files it dumps seems 'corrupt' in Ubuntu. Those cannot be loaded by the SimpleITK in python wrapper.
But, it works fine in Windows OS!
What is going wrong?

Event Timeline

a178n triaged this task as Normal priority.Oct 10 2023, 3:01 PM
a178n created this task.

This is the sample NRRD file written by the above mentioned writer function. It can't be opened in Python or by

.
Error log:

Exception occurred when reading file /tmp/mitk-sam-OBvksy/sam-in-QOdQsN/3111588501110146159.nrrd:
/home/user1/DKFZ/nnUNet_work/MITK_nnunet/build/ep/src/ITK/Modules/IO/NRRD/src/itkNrrdImageIO.cxx:292:
itk::ERROR: NrrdImageIO(0x561dd4b8c4b0): ReadImageInformation: Error reading /tmp/mitk-sam-OBvksy/sam-in-QOdQsN/3111588501110146159.nrrd:
[nrrd] nrrdLoad: trouble reading "/tmp/mitk-sam-OBvksy/sam-in-QOdQsN/3111588501110146159.nrrd"
[nrrd] nrrdRead: trouble
[nrrd] _nrrdRead: trouble reading NRRD file
[nrrd] _nrrdFormatNRRD_read: trouble parsing space origin info |(-185,04367065429688,-161,31900024414062)|
[nrrd] _nrrdReadNrrdParse_space_origin: couldn't parse origin "(-185,04367065429688,-161,31900024414062)"
[nrrd] _nrrdSpaceVectorParse: space dimension is 2, but seem to have 4 coefficients

most likely it is due to wrong locales in the out stream operation on your OS. You have ',' in your file where '.' should be.

Use mitkLocaleSwitch before the write operation. See documentation of the locale switch.

Yes, that was it. Works now!