QIICR / dcmqi

dcmqi (DICOM for Quantitative Imaging) is a free, open source C++ library for conversion between imaging research formats and the standard DICOM representation for image analysis results
https://qiicr.gitbook.io/dcmqi-guide/
BSD 3-Clause "New" or "Revised" License
234 stars 62 forks source link

Conversion to SEG results in incorrect geometry of the result #473

Closed fedorov closed 9 months ago

fedorov commented 1 year ago
image

Dataset to reproduce the issue is not public.

fedorov commented 9 months ago

@michaelonken can you look into this? I can provide the dataset!

michaelonken commented 9 months ago

Sure, I'll handle it.

fedorov commented 9 months ago

Looking at the screenshot, SEG size is shown as 288x16, while CT series shows 16 slices - perhaps this is the first thing to check if somehow the dimensions were not mixed up in the conversion? It might be that orientation of the segmentation NIfTI was not the same as the orientation of the DICOM CT. Although, at the same time, it doesn't have to be identical ... Not sure.

fedorov commented 9 months ago

Michael, I think the issue is here: https://github.com/QIICR/dcmqi/blame/master/libsrc/Itk2DicomConverter.cpp#L93

I think the rows/colums spacing needs to be swapped. Here is the corresponding part of the standard: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_10.7.html#sect_10.7.1.3.

This came up before, when I fixed it on read in https://github.com/QIICR/dcmqi/issues/425, but I missed to also fix it on write!

pieper commented 9 months ago

rows/colums spacing needs to be swapped

Yes, this is a quirk in the standard that people might easily miss since it doesn't come up much in practice.

https://github.com/Slicer/Slicer/blob/2f04e07a57b4565127864bde603265181cc01a49/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L802-L805

fedorov commented 9 months ago

@dclunie I think we had this conversation at some point about non-square pixels. This specific example demonstrated how easy it is to make non-square pixels while converting to DICOM SEG.

In this case, I do not know if this is intentional or unintentional, but the original MR image was 0.5x0.5 in-plane and 3mm between slices 128x128 rows/cols and 16 slices. The segmentation they created in NIfTI reformatted the pixel matrix to make the slice 128x16 rows/cols and 128 slices. In this case, I can hardly imagine a valid reason for re-formatting rows/columns/slices. Most likely it's just due to DICOM-NIfTI-DICOM process, but nevertheless, the result is 0.5x3 mm pixel size.

michaelonken commented 9 months ago

Michael, I think the issue is here: https://github.com/QIICR/dcmqi/blame/master/libsrc/Itk2DicomConverter.cpp#L93

I think the rows/colums spacing needs to be swapped. Here is the corresponding part of the standard: https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_10.7.html#sect_10.7.1.3.

This came up before, when I fixed it on read in #425, but I missed to also fix it on write!

This does the trick 🥳.

See PR https://github.com/QIICR/dcmqi/pull/486 which switches x and y pixel spacing when converting from ITK to DICOM.

fedorov commented 9 months ago

Resolved by #486.