Unable to write dicom file with double values

Hi,
I set pixel value of image with double value and tried to save image as dicom file. I am getting error like this
“Description: itk::ERROR: GDCMImageIO(0573B7B0): A Floating point buffer was passed but the stored pixel type was not specified.This is currently not supported”.

typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(“D:\testdicom.dcm”);
writer->SetImageIO(itk::GDCMImageIO::New());
writer->SetInput(dicomData);
try
{
writer->Update();
}
catch (itk::ExceptionObject& error)
{
std::cerr << "Error: " << error << std::endl;
}

Can any one help me in this?

Thanks & Regards
Hasna

1 Like

Most DICOM modalities doesn’t support double or float precision pixel values, if you really want this you could use the modality “Parametric Map” but I’m unsure if the ImageFileWriter supports this. Usually you can only store pixel values as 16-bit integers and then use intercept/slope parameters to reconstruct the data. Of course you usually get a quantization error when doing this depending on the original data.

1 Like

Thank you for you help. I will try to reconstruct the data.

Thank you mattias for the help.
I will try to reconstruct the data with parameters.

As I mentioned there are some modalities that supports 32 or 64-bits, “Parametric Map” and perhaps “Secondary Capture”, but I’m uncertain how the ITK image writer works and what the resulting modality is.

Ok . I will also look into it.

Thank you.

Secondary Capture sounds familiar, that is more likely to work than Parametric Map.

@mihail.isakov and @mathieu.malaterre might have more suggestions.

AFAIK, GDCM currently doesn’t support float (0x7fe0,0x0008) and double (0x7fe0,0x0009) pixel data, i do in my production clone, but it is big change.

All the above is correct.

ITK currently only does “16bits floating point buffer”. So you need to use the Rescale Slope/Intercept to get a float16 buffer approximation of your original dataset.

GDCM does not implement support f(read+write) of Parametric Map, this is rather a big change and very few DICOM viewers support them (AFAIK).

Thank you for the information.
Now i am trying to add header tag data for rescale intercept . The writer is throwing exception.

Unhandled Exception: System.Runtime.InteropServices.SEHException: External component has thrown an exception.
   at itk.ImageFileWriter<itk::Image<short,2> >.GenerateData(ImageFileWriter<itk::Image<short\,2> >* ) in C:\ITK_4.13_x86_vs17\ITK\include\ITK-4.13\itkImageFileWriter.hxx:line 429
   at itk.ImageFileWriter<itk::Image<short,2> >.Write(ImageFileWriter<itk::Image<short\,2> >* ) in C:\ITK_4.13_x86_vs17\ITK\include\ITK-4.13\itkImageFileWriter.hxx:line 363
   at itk.ImageFileWriter<itk::Image<short,2> >.Update(ImageFileWriter<itk::Image<short\,2> >* ) in C:\ITK_4.13_x86_vs17\ITK\include\ITK-4.13\itkImageFileWriter.h:line 165

This is the code

using DictionaryType = itk::MetaDataDictionary; 
	DictionaryType& dictionary = inputImage->GetMetaDataDictionary();

 std::string rescaleIntercept("0028|1052");
		std::string rescaleInterceptValue("0");
		itk::EncapsulateMetaData<std::string>(dictionary, rescaleIntercept, rescaleInterceptValue);

		std::string rescaleSlope("0028|1053");
		std::string rescaleSlopeValue("1000");
		itk::EncapsulateMetaData<std::string>(dictionary, rescaleSlope, rescaleSlopeValue);

I am not able to update only these two tags. Along with it i changed 2 more tags (“0008|0016” and 0018|6032) .Those are getting updated. But not rescale tags.
Any help is appreciated.

Thanks & Regards
Hasna