Add configuration to allow using itk or pydicom_seg for DICOM SEG #1854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When working with DICOM images and running inferences to generate DICOM Segs, the ITK tool (
itkimage2segimage) can sometimes fail: even if MONAILabel successfully produces a segmentation, converting it to a DICOM Seg may abort if a required tag is missing, as shown next, which aborts all the process and in the end no segmentation is returned.E: CodingSchemeDesignator (0008,0102) absent in CodeSequenceMacro (type 1) E: Could not write item #0 in ProcedureCodeSequence: Invalid Value FATAL ERROR: Writing of the SEG dataset failed! Error: Invalid Value. Please report the problem to the developers, ideally accompanied by a de-identified dataset allowing to reproduce the problem! ERROR: Conversion failed.To solve this error, a fix is presented here (https://qiicr.gitbook.io/dcmqi-guide/faq#conversion-fails-with-the-missing-attribute-s-error-what-should-i-do), but this is not optimal when dealing with real DICOM data, where files are constantly incoming to the PACS, since it requires to modify the attribute in all dicom files.
Since MONAILabel already supports
pydicom_segfor DICOM SEG generation, this PR introduces a way to switch between theitkimage2segimagetool andpydicom_seg, which was previously hardcoded and could not be changed unless we changed the code.Summary
MONAI_LABEL_USE_ITK_FOR_DICOM_SEGinmonailabel/config.py, overridable via environment variable. Default is True to preserve existing behavior.nifti_to_dicom_seginmonailabel/datastore/utils/convert.pyto respect this setting. The function can still override the config if needed; the setting only applies when use_itk is None.Test Plan