Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting nifti to dicom-seg fails silently when referenced series is not fully DICOM compliant #105

Open
vanossj opened this issue Oct 17, 2024 · 3 comments

Comments

@vanossj
Copy link
Contributor

vanossj commented Oct 17, 2024

This problem came up from this issue when I tried to run the bamf_nnunet_ct_kidney model on a ct scan from TCGA-KIRC.

The issue is with series 1.3.6.1.4.1.14519.5.2.1.6450.4004.318185778053926832345567953536, you can reproduce the issue with the code below.

Download the series from the IDC

from idc_index import index
from pathlib import Path

Path("example_data").mkdir(exist_ok=True)

client = index.IDCClient()
client.download_from_selection(
    seriesInstanceUID=["1.3.6.1.4.1.14519.5.2.1.6450.4004.318185778053926832345567953536"],
    downloadDir="example_data",
)

Run the bamf_nnunet_ct_kidney model

mkdir example_output
export in=$(pwd)/example_data
export out=$(pwd)/example_output

docker run --rm -t --gpus all -v $in:/app/data/input_data -v $out:/app/data/output_data mhubai/bamf_nnunet_ct_kidney

On my system it took about 12 minutes to run. Then finished with no warnings or errors, but the example_output directory was empty.

@jithenece dug in a bit and found that itkimage2segimage is reporting an error with the CT scan not being compliant with the dicom standard. He went into the container and ran
itkimage2segimage --inputImageList VOLUME_001.nii.gz --inputDICOMDirectory dicom --outputDICOM seg.dcm --inputMetadata temp-meta.json

which gave the output:

DEBUG - Writing per-frame group: Frame Content Functional Group Macro for frame #65
DEBUG - Writing per-frame group: Plane Position (Patient) Functional Group Macro for frame #65
DEBUG - Writing per-frame group: Segmentation Functional Group Macro for frame #65
DEBUG - Writing component: DimensionOrganizationSequence
DEBUG - Writing component: DimensionIndexSequence
DEBUG - Writing component: DimensionIndexSequence
DEBUG - Writing component: MultiframeDimensionModule
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: SOPCommonModule
DEBUG - Writing component: PatientModule
DEBUG - Writing component: PatientStudyModule
DEBUG - Writing component: HL7HierarchicDesignatorMacro
DEBUG - Writing component: CodeSequenceMacro
ERROR - CodingSchemeDesignator (0008,0102) absent in CodeSequenceMacro (type 1)
ERROR - Could not write item #0 in ProcedureCodeSequence: Missing Attribute(s)
FATAL ERROR: Writing of the SEG dataset failed! Error: Missing Attribute(s). Please report the problem to the developers, ideally accompanied by a de-identified dataset allowing to reproduce the problem!
ERROR: Conversion failed.

I did run into these issues when working on AIMI, my solution was just to smash the referenced dicom into some sort of compliance so that itkimage2segimage would generate the segmentation image.

This is the script I used to fix various dicom issues I came across as I worked on AIMI, but I would hope there is a better alternative somewhere out there for fixing dicom files.

It would be useful to have the DsegConverter step report the error

@LennyN95
Copy link
Member

Thank you for the detailed report! We have a cli argumen --stop-on-error which will halt execution if an error occurs (in combination with --print the error message is routed to the stdout instead of the log files).

How we'll deal with incompliant dicom files could lead to an interesting discussion where I can see multiple strategies:

  • we fail on incompatible scans
  • we check for compatibility and report issues
  • we attempt to auto-fix incompatible scans (upon explicit request)

@LennyN95
Copy link
Member

@fedorov

@fedorov
Copy link
Member

fedorov commented Oct 18, 2024

It's a known issue, unfortunately - related to QIICR/dcmqi#232.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants