I am reading in a dicom image via GDCM as unsigned short. The pixel representation of the imported dicom image is 0 (unsigned short). I confirmed that the component type and internal component types are USHORT. I am then writing out the image again to dicom using the gdcm writer. The outputted file has Pixel Representation of 1 (2’s complement). I didn’t check explicitly, but I assuming that the pixel data is in 2’s complement.
I would like to ensure that the outputted data is consistent with the inputted data (pixel representation =0, unsigned short), but I cannot find anyway to change the way the data is outputted, nor can I figure out why the data is written out as a 2’s complement in the first place, especially when I checked that the internal and regular component types are both USHORT.
i found the issue. I had instantiated the reader type as signed short not unsigned. this forces the output to pixel representation =1 (2’s complement), even thought the component type and internal component types were unsigned short. When defining the reader class as an unsigned short and outputting, then the pixel representation and data is outputted as 0 (unsigned short). However, i am still confused about how the rescale slope and intercept are handled. I believe they are applied during reading, which should force the data to negative values (if intercept is -1000, which it normally is). Then upon exporting it is reversed putting the data back to unsigned short. I am not 100% sure how to handle this situation. Should i instantiate the reader as signed or unsigned? If it is unsigned, i am guessing that the rescale slope and intercept would not force the data properly to negative values. But in this case the export would have the proper pixel representation of 0 (unsigned again) but potentially be wrong when the rescale slope and intercept is reversed prior to export?
For reading, signed short seems like the right choice. Writing DICOMs has many pitfalls. Maybe @mihail.isakov, @mathieu.malaterre, or @lassoan have some suggestions?
In 3D Slicer we read into float pixel type to avoid data loss due to rescaling; and we support writing signed/unsigned char, short, int images (DICOM has float voxel type for a while, but it is not very commonly implemented in applications, so we haven’t added support for writing float type).
I would not worry too much about changing the output voxel type to signed/unsigned. The written DICOM file will be quite different from the input DICOM file anyway (different UIDs, creator software information, maybe image type and other things as well).