Repository navigation
BUG: Make unit DICOM foreground values opt-in - #7175
ayaanrustagi wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Thank you for contributing a pull request! 🙏
Welcome to the ITK community! 🤗👋☀️
We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
More support and guidance on the contribution process can be found in our contributing guide. 📖
This is an automatic message. Allow for time for the ITK community to be able to read the pull request and comment
on it.
hjmjohnson
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. Two CI failures and a design question block this for now.
- The existing
itkGDCM_ComplianceTest_singlebitfails (ARMBUILD-Ubuntu-24.04-arm). Its inputInput/single-bit.dcmis already a Segmentation Storage object (SOP class 1.2.840.10008.5.1.4.1.1.66.4, BINARY, 128x128x16), andBaseline/single-bit.mhastores 255 for its foreground. With this change 4089 voxels read as 1, a difference of 254 each. The "existing one-bit cases pass" note in the PR body covers only the two GTests, which write non-SEG (OT) files. - The new fixture is not reachable from any ExternalData mirror, so the ExternalData build step fails,
ITKIOGDCMGTestDriveris not built, and the remaining*_NOT_BUILTfailures on the other jobs follow from that. The test file can build the SEG itself, see the inline comment, which removes the hosting question entirely. - Silent behavior change. Code that reads a BINARY SEG through GDCMImageIO (ITK, SimpleITK
ReadImage,itk.imread) and thresholds or compares against 255 keeps compiling and silently gets an empty mask. Could this be opt-in onGDCMImageIO, default 255, so existing results and the compliance baseline stay valid? If the default should change, that needs a stated downstream impact, an ITKv6 migration-guide entry, a commit body explaining it, and a newsingle-bit.mhabaseline.
Not addressed here, for the record: in a multi-segment BINARY SEG every segment still reads as 1, so per-segment identity is not recovered either way.
| gdcm::MediaStorage mediaStorage; | ||
| mediaStorage.SetFromFile(reader.GetFile()); | ||
| // Binary segmentation foreground represents label 1 (DICOM PS3.3 C.8.20.2). | ||
| const unsigned char foreground = mediaStorage == gdcm::MediaStorage::SegmentationStorage ? 1 : 255; |
There was a problem hiding this comment.
should-fix: this flips every existing BINARY SEG read from 255 to 1, including the one itkGDCM_ComplianceTest_singlebit checks against Baseline/single-bit.mha (fails in CI). Suggest an opt-in instead, e.g. a SetSingleBitForegroundValue(unsigned char) or a boolean for SEG, default 255, so existing results do not change. Also, ReadImageInformation already resolves gdcm::MediaStorage (around line 657); deciding the foreground there next to m_SingleBit avoids a second SetFromFile per Read() (nit).
| // used when `len` is not a multiple of 8. | ||
| gdcm::MediaStorage mediaStorage; | ||
| mediaStorage.SetFromFile(reader.GetFile()); | ||
| // Binary segmentation foreground represents label 1 (DICOM PS3.3 C.8.20.2). |
There was a problem hiding this comment.
nit: in a BINARY SEG a set bit means "inside the segment this frame's Referenced Segment Number names", not label 1, and a multi-segment SEG still reads every segment as 1. Something like // BINARY Segmentation Storage stores segment presence as 1 (PS3.3 C.8.20.2.1). is more accurate. These four lines also landed between the PS3.5 bit-packing comment and the loop it describes; moving them above that comment keeps the two together.
|
|
||
| TEST_F(ITKGDCMImageIO, BinarySegmentationStoragePreservesUnitForeground) | ||
| { | ||
| constexpr size_t width = 16; |
There was a problem hiding this comment.
should-fix: the hosted fixture can be replaced by an in-test SEG. WriteSingleBitDicom (and WriteMultiFrameSingleBitDicom) can take an optional SOP class and set (0008,0016); gdcm::Writer copies it into (0002,0002) when writing, and MediaStorage::SetFromFile prefers the dataset value anyway. Sketch (not compiled):
// helper: extra parameter, after the pixelRepresentation Replace
gdcm::MediaStorage::MSType sopClass = gdcm::MediaStorage::MS_END
...
if (sopClass != gdcm::MediaStorage::MS_END)
{
gdcm::Attribute<0x0008, 0x0016> sopClassUid;
sopClassUid.SetValue(gdcm::MediaStorage::GetMSString(sopClass));
ds.Replace(sopClassUid.GetAsDataElement());
}Then use sizes that are not a multiple of 8 (e.g. 9x3, and 12x13x8 multi-frame): 16x16 never reaches the remainder loop that this PR also changed. With pixels synthesized as 0/1, the expected value is the input itself, which also replaces the hard-coded index list on line 707 that cannot be checked from the repo. The existing tests at lines 605 and 766 keep pinning the non-SEG 255 path.
| _DICOM_SERIES_INPUT | ||
| "DATA{${ITK_DATA_ROOT}/Input/DicomSeries/,REGEX:Image[0-9]+.dcm}" | ||
| ) | ||
| ExternalData_Expand_Arguments( |
There was a problem hiding this comment.
should-fix: with the SEG built in-test, this ExternalData_Expand_Arguments block, the BINARY_SEG_INPUT definition, Input/SyntheticBinarySegmentation.dcm.cid, and the content-links.manifest line can all go (they have to go together; a DATA{} reference without its .cid breaks configure).
|
Thanks for identifying the compatibility test. The latest commit keeps the default foreground value at 255 and adds All eight GDCMImageIO GoogleTests and |
hjmjohnson
left a comment
There was a problem hiding this comment.
This looks like a better solution than your original hard-coding. It is more backward compatible for those who depend on the old behavior.
[Medium impact] The PR appears safe to merge; no actionable issues were found.
|
Add an opt-in foreground value for single-bit DICOM reads. Preserve the existing default of 255 and generate the SEG regression input in the test.
Behavior and tests
Set
GDCMImageIO::SetSingleBitForegroundValue(1)to read the set bits as 1. This changes their magnitude only. It does not recover individual segment IDs in multisegment SEG objects.The regression test generates single-frame and multiframe SEG inputs with partial final bytes. It checks every output pixel in the default and opt-in modes. The existing one-bit compliance image remains the compatibility test for the default. The generated fixture removes the need for a new ExternalData object. All eight GDCMImageIO GoogleTests and the existing single-bit compliance test passed locally.
Addresses the foreground-value portion of #6641. Labelmap opening and orientation failures are separate.
AI assistance
Codex helped implement the changes and run the automated checks. The PR remains a draft while human verification and maintainer review are pending.