Skip to content

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

Merged
wayfarer3130 merged 3 commits into
1.0-betafrom
fix/1.0-beta-port-603-multiframe-groups
Nov 25, 2026
Merged

wayfarer3130 merged 3 commits into
1.0-betafrom
fix/1.0-beta-port-603-multiframe-groups

Conversation

@wayfarer3130

@wayfarer3130 wayfarer3130 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR is the 1.0 port of #603 from 0.x. The PR also changes the NumberOfFrames rule of #603 (see "Maintainer edits").

Summary

normalizeMultiframe in src/normalizers.js read a missing SharedFunctionalGroupsSequence and threw a TypeError (OHIF #6307). This PR ports the merged fix of #603 to the 1.x line. The normalizer now fills the missing functional groups from the top-level attributes. A SEG derivation on the result does not throw.

Cause

  • normalizeMultiframe logged an error when SharedFunctionalGroupsSequence was missing, and then wrote PixelValueTransformationSequence into the missing sequence.
  • When NumberOfFrames was 1, the frame loop wrapped PerFrameFunctionalGroupsSequence in an array, also when the value was already an array. A missing sequence became [undefined], and the loop threw on FrameContentSequence.

Changes

src/normalizers.js is the only copy of the normalizer in 1.x. No package in packages/* has a copy, so this PR changes that one file.

  • Two new static methods, ImageNormalizer.sharedImagePlaneGroups(dataset, pixelMeasures) and ImageNormalizer.planePositionGroup(dataset), build the image plane groups from the top-level attributes. convertToMultiframe now calls both methods. The output of convertToMultiframe does not change.
  • When SharedFunctionalGroupsSequence is missing, normalizeMultiframe builds PlaneOrientationSequence (ImageOrientationPatient) and PixelMeasuresSequence (PixelSpacing, SliceThickness, SpacingBetweenSlices).
  • When PerFrameFunctionalGroupsSequence is missing, normalizeMultiframe builds one item for each frame of NumberOfFrames. Each item has PlanePositionSequence (the top-level ImagePositionPatient) and its own FrameContentSequence (InStackPositionNumber and DimensionIndexValues 1 to N). A sequence that is not an array gets one wrap. A sequence that is an array stays as it is.
  • log.error becomes log.warn: "Missing SharedFunctionalGroupsSequence; using the top-level image plane attributes".
  • test/segIncompleteMultiframe.test.js is new.
  • test/bundle-size.test.js: the ceilings change from 1.083 to 1.085 (dcmjs.js) and from 1.065 to 1.067 (dcmjs.es.js). The ceiling comment is now one line.

The NumberOfFrames rule

  • The normalizer keeps the declared NumberOfFrames. The normalizer does not count the frames in PixelData.
  • The size of PixelData does not tell the number of frames. Encapsulated PixelData can have more fragments than frames. Encapsulated PixelData can also have fewer fragments than frames, for example in the video transfer syntaxes.
  • With NumberOfFrames N and no PerFrameFunctionalGroupsSequence, the result has N per-frame items.

Bundle size

The ceilings come from a local build of 1.0-beta with #660, #659 and this PR merged, in that order. The intended merge order is #660, #659, #662, and #658 last.

Build dcmjs.js dcmjs.es.js
This PR alone ×1.0834 (1499933 bytes) ×1.0659 (1446868 bytes)
#660 + #659 + #662 ×1.0841 (1500851 bytes) ×1.0665 (1447731 bytes)
Ceiling 1.085 1.067

Verified

  • Before the fix of fix(normalizers): normalize multiframe datasets missing functional group sequences #603: test/segIncompleteMultiframe.test.js with the src/normalizers.js of 1.0-beta gives 3 failures and 1 pass (the control). The failures are TypeError: Cannot set properties of undefined (setting 'PixelValueTransformationSequence') (the SEG test with includeSliceSpacing true and false) and TypeError: Cannot set properties of undefined (setting 'FrameContentSequence') (the NumberOfFrames: 1 test).
  • Before the NumberOfFrames change: the updated test file gives 4 failures and 2 passes. The SEG tests got NumberOfFrames 1, not 4. The test with 2 fragments of 10 bytes got NumberOfFrames 2, not 8. The test with 10 fragments kept 8 frames, but got 1 per-frame item, not 8.
  • After the change, npx jest --runInBand passes on these files: segIncompleteMultiframe (6 tests), normalizers, derivations, compat-052, data, package-exports, bundle-size.
  • eslint and prettier --check on the changed files: no findings.
  • pnpm run build: pass.
  • I did not run the full test suite locally. CI runs the full suite.

Behaviour changes

  • A dataset with a multiframe SOP class and no functional groups now normalizes. Before this PR, the normalizer threw a TypeError.
  • NM Image is in the multiframe SOP class list, and an NM Image has no functional groups. Thus every NM Image now goes through this path, and the normalizer adds the functional groups. Before this PR, the normalizer threw on an NM Image.
  • A one-frame enhanced dataset whose per-frame sequence is an array now stays [item]. Before this PR, the result was [[item]], and FrameContentSequence went on the inner array, not on the item.

Maintainer edits

Not ported and why

🤖 Generated with Claude Code

…oups (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]>
wayfarer3130 and others added 2 commits November 25, 2026 08:13
…oups 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]>
…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]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 25, 2026 14:06
@wayfarer3130
wayfarer3130 merged commit 0e9d3d4 into 1.0-beta Nov 25, 2026
4 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/1.0-beta-port-603-multiframe-groups branch November 25, 2026 14:07
wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…oups 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. Same change as the
1.x port #662.

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 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 26, 2026
…magePositionPatient array per frame (#665)

* fix(normalizers): treat an empty per-frame sequence as missing; one ImagePositionPatient array per frame

An empty PerFrameFunctionalGroupsSequence no longer reduces the number
of frames: the normalizer builds one item per declared frame, as for a
missing sequence. Each generated item gets its own ImagePositionPatient
copy. Port of the 0.x fix in #664 (follow-up to #662).

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

* fix(normalizers): treat an empty shared sequence as missing; complete the per-frame sequence

- An empty SharedFunctionalGroupsSequence array counts as missing, and a
  one-item array is used as its item, so the shared groups the normalizer
  sets (PixelValueTransformationSequence and the others) are written.
- The per-frame sequence is filled up to NumberOfFrames, and each item
  gets its FrameContentSequence, not only the first item.
- planePositionGroup passes a non-array ImagePositionPatient through.
- Raise the dcmjs.js bundle ceiling to x1.091 (measured x1.09014).

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

* fix(normalizers): keep an existing FrameContentSequence; replace a null per-frame item

- The normalizer adds a FrameContentSequence only to a per-frame item
  that has none; an existing item keeps its own (dimension index values,
  temporal position, stack ID).
- A null or missing per-frame item becomes an empty item again, so
  [null, {}] no longer throws a TypeError.
- Tests: an existing item keeps its FrameContentSequence, and the shared
  groups survive a denaturalize/naturalize round trip.

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

* fix(normalizers): keep the shared group accessors and skip null items after NumberOfFrames

- Call addAccessors on the SharedFunctionalGroupsSequence item, so that
  both SharedFunctionalGroupsSequence.X and SharedFunctionalGroupsSequence[0].X
  work, also for a hand-built one-item array.
- The window guess skips a null per-frame item after NumberOfFrames and
  does not throw.
- Tests: a [null, {}] case in the completes-a-per-frame-sequence it.each,
  a null item after NumberOfFrames, a one-item shared array. The test
  "keeps a complete multiframe dataset unchanged" now uses NumberOfFrames 1.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant