Skip to content

fix(normalizers): normalize multiframe datasets missing functional group sequences - #603

Merged
wayfarer3130 merged 7 commits into
dcmjs-org:masterfrom
entity-0-0-2:fix/single-frame-multiframe-seg
Nov 24, 2026
Merged

wayfarer3130 merged 7 commits into
dcmjs-org:masterfrom
entity-0-0-2:fix/single-frame-multiframe-seg

Conversation

@entity-0-0-2

@entity-0-0-2 entity-0-0-2 commented Oct 10, 2026 •

Copy link
Copy Markdown

This PR normalizes a multiframe dataset that has no functional group sequences. Before this PR, the normalizer threw TypeError: Cannot set properties of undefined (setting 'PixelValueTransformationSequence').

Problem

ImageNormalizer.normalizeMultiframe detects a missing SharedFunctionalGroupsSequence. The method only logs an error, and then it uses the missing sequence. Later, the method indexes PerFrameFunctionalGroupsSequence, and that sequence can also be missing.

A single dataset with a multiframe SOP class and no functional groups makes the normalizer crash. An example of such a dataset is one frame that a caller extracts from an enhanced multiframe instance.

OHIF/Viewers#6307 reports this crash with this stack: SEGImageNormalizer.normalizeMultiframe → normalize → _createMultiframeSegmentationFromReferencedImages. cornerstonejs/cornerstone3D#2919 tracks the fix on the caller side. This PR makes the dcmjs side safe. The reported input now normalizes, and the SEG derivation (Segmentation and addSegmentFromLabelmap) that follows also completes on that input.

Root cause

  • src/normalizers.js:330-334 (on master) logs "Can only process multiframe data with SharedFunctionalGroupsSequence". The code does not initialize the sequence before line 350 writes PixelValueTransformationSequence.
  • Lines 355-363 expect that PerFrameFunctionalGroupsSequence[frameNumber - 1] exists.
  • The pattern "log, then use the missing sequence" dates to 291adc0 (2017). In that commit, the sequence had the name SharedFunctionalGroups.

Fix

When SharedFunctionalGroupsSequence is missing, normalizeMultiframe now does these steps:

  • It builds PlaneOrientationSequence (ImageOrientationPatient) and PixelMeasuresSequence (PixelSpacing, SliceThickness, and SpacingBetweenSlices when present) from the top-level attributes.
  • It reduces NumberOfFrames to the number of whole frames that PixelData holds, when PixelData holds fewer frames. A caller that extracts one frame can keep the NumberOfFrames of the source instance. The OHIF #6307 input had NumberOfFrames: 4 and 1 frame of pixels.
  • It logs a warning, not an error, because the normalizer now continues.

When PerFrameFunctionalGroupsSequence is missing, the normalizer builds one item with PlanePositionSequence (ImagePositionPatient). The normalizer wraps the sequence in an array only when the sequence is not an array. Thus a dataset with NumberOfFrames: 1 gets an object as the per-frame item, and not an array.

convertToMultiframe already built these groups from the top-level attributes. The two methods now share the code in ImageNormalizer.sharedImagePlaneGroups and ImageNormalizer.planePositionGroup.

For a complete multiframe dataset, the result does not change, with one exception. Before this PR, a per-frame sequence that was already an array, with NumberOfFrames: 1, got a second array around it ([[item]]). Now the sequence stays [item].

Tests

test/segIncompleteMultiframe.test.js has these tests:

  • A single dataset with an Enhanced MR SOP class UID, NumberOfFrames: 4, 1 frame of pixels, and no functional group sequences. The test runs SEGImageNormalizer.normalize(). The test asserts NumberOfFrames: 1, the shared orientation and pixel spacing, and the per-frame position. Then the test runs new Segmentation(...) and addSegmentFromLabelmap, with includeSliceSpacing true and false. The test asserts the position in the SEG per-frame item.
  • A dataset with NumberOfFrames: 1 and no per-frame sequence. The test asserts that the per-frame item is an object, and not an array.
  • A control: a complete multiframe dataset does not change.

On master, the first test fails with Cannot set properties of undefined (setting 'PixelValueTransformationSequence') at src/normalizers.js:350. On the earlier head of this PR, the first two tests fail. With this change, all tests pass, and test/normalizers.test.js and test/derivations.test.js also pass.

Maintainer edits

  • Merged master into the branch, after fix(orientation): allocate matrix transform output with the input typed array type #602 merged. The diff now holds only the change of this PR.
  • Added the image plane groups and the NumberOfFrames rule above, so that the SEG derivation also completes on the reported input.
  • Fixed the [[]] per-frame item for NumberOfFrames: 1.
  • Changed log.error to log.warn, with a message that is true.
  • Made the test assertions stronger: the frame count and the geometry.

@netlify

netlify Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit b17889d
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6ac993033a0a2c0008787f37
😎 Deploy Preview https://deploy-preview-603--dcmjs2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit 19f840a
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6b0617da966119b3d8cfc6dc
😎 Deploy Preview https://deploy-preview-603--dcmjs2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

wayfarer3130 and others added 2 commits November 24, 2026 18:01
…set has none

When SharedFunctionalGroupsSequence is missing, normalizeMultiframe now
fills PlaneOrientationSequence and PixelMeasuresSequence from the
top-level attributes, and the per-frame PlanePositionSequence from
ImagePositionPatient. The code is shared with convertToMultiframe.
NumberOfFrames is reduced to the number of frames that PixelData holds,
so the SEG derivation no longer throws on one frame taken from a
multiframe instance (OHIF #6307).

A missing per-frame sequence with NumberOfFrames 1 now gives an object
item, not [[]]. The missing-groups message is a warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 merged commit d65022d into dcmjs-org:master Nov 24, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.53.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…oups (port of #603) (#662)

* fix(normalizers): normalize multiframe datasets missing functional groups (port of #603)

normalizeMultiframe dereferenced a missing SharedFunctionalGroupsSequence
and threw a TypeError. When the groups are missing, fill the shared
PlaneOrientationSequence / PixelMeasuresSequence and the per-frame
PlanePositionSequence from the top-level attributes, through the static
ImageNormalizer.sharedImagePlaneGroups and planePositionGroup that
convertToMultiframe now also uses. Lower NumberOfFrames to the whole
frames PixelData holds (never raise it), with a warning. A per-frame
sequence that is already an array is no longer wrapped again, so a
one-frame item is an object and not [[item]]. log.error becomes log.warn.

Raise the bundle-size ceilings to 1.084 and 1.067 for the ~1.7 KB added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(normalizers): keep the declared NumberOfFrames when functional groups are missing

The normalizer no longer lowers NumberOfFrames to the frames that PixelData
appears to hold. Encapsulated PixelData can have more or fewer fragments than
frames, so a byte count says nothing about the frame count. framesInPixelData
is removed.

A dataset with no PerFrameFunctionalGroupsSequence now gets one per-frame item
for each declared frame, each with PlanePositionSequence from the top-level
ImagePositionPatient and its own FrameContentSequence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(bundle-size): set the ceilings from a build with #660, #659 and #662

The combined build measures x1.0841 (dcmjs.js) and x1.0665 (dcmjs.es.js).
The ceiling comment is now one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants