Repository navigation
fix(normalizers): treat an empty per-frame sequence as missing; one ImagePositionPatient array per frame - #665
Merged
Conversation
…magePositionPatient 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]>
… 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]>
…ll 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]>
… 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]>
# Conflicts: # test/bundle-size.test.js
wayfarer3130
marked this pull request as ready for review
November 26, 2026 01:27
wayfarer3130
added a commit
that referenced
this pull request
Nov 26, 2026
…t of #665) - An empty SharedFunctionalGroupsSequence array counts as missing. A one-item array gets the list accessors (addAccessors), so the shared groups the normalizer sets are written. A plain object stays as is. - The per-frame sequence is filled up to NumberOfFrames. Existing items keep their content, and only an item without a FrameContentSequence gets one. - A null per-frame item becomes an empty item; a null item after NumberOfFrames is kept and the window guess does not throw. - planePositionGroup copies an array ImagePositionPatient per frame and passes a non-array value through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.22 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR is a follow-up to #662. PR #662 is the 1.x port of #603, which normalizes a multiframe dataset that has no functional groups. The merged 1.x code has defects in
src/normalizers.js. The first commit (3a7e159) ports the 0.x fix of #664 (commit4b0b844). The second commit (07f8324) fixes three more defects that the review of this PR found. The third commit (83fdb5e) fixes two defects that the review of07f8324found. The fourth commit (8223bec) applies the decisions of the final review. The merge commit (20809da) merges1.0-betawith #663 and #666.Defects
normalizeMultiframetreatsPerFrameFunctionalGroupsSequence: []as a sequence that is present. For an input withNumberOfFrames8 and one source dataset, the result has 1 per-frame item, not 8.ImageNormalizer.planePositionGroupputs the sameImagePositionPatientarray object in each per-frame item. A change to the position of one frame changes the position of all frames.normalizeMultiframetreatsSharedFunctionalGroupsSequence: []as present. The normalizer does not build the plane orientation and the pixel measures. The normalizer then setsPixelValueTransformationSequenceas a named property of the array, and the writer drops that property. The same loss occurs for a shared sequence that is an array of one item. In 1.0,naturalizeDatasetdoes not give this array for a real file: it gives the item object with[0]andlengthaccessors (addAccessors). A one-item array comes from a dataset that code builds by hand, or from the 0.x shape, for exampleJSON.parseof a 0.x dataset.FrameContentSequenceonly to item 1 for a multiframe source. A per-frame sequence with fewer items thanNumberOfFramesstays short.ImagePositionPatient. The copy of N6 used?.slice(), and a number value gave aTypeError.nullper-frame item afterNumberOfFrames. The window guess reads every per-frame item. Anullitem afterNumberOfFramesgaveTypeError: Cannot read properties of null (reading 'FrameVOILUT'). The base branch has the same defect.Fix
The change is in
src/normalizers.js:normalizeMultiframetreats an emptyPerFrameFunctionalGroupsSequencearray the same as a missing sequence. The normalizer keeps the declaredNumberOfFrames(decision Q1 of fix(normalizers): normalize multiframe datasets missing functional groups (port of #603) #662).normalizeMultiframeuses item 1 of aSharedFunctionalGroupsSequencearray as the shared group. An empty array thus counts as missing, and the normalizer builds the shared groups from the top-level attributes. All other code insrc/reads the shared group as one object.normalizeMultiframecallsaddAccessors(from@dcmjs-org/core) on the shared group. BothSharedFunctionalGroupsSequence.XandSharedFunctionalGroupsSequence[0].Xthus work after the normalizer. This is also true for a one-item array that code builds by hand, and for a shared group that the normalizer builds.normalizeMultiframefills the per-frame sequence up toNumberOfFramesitems. A new item has the top-level position, the same as for a missing sequence. An existing item keeps its content.normalizeMultiframeadds aFrameContentSequenceonly to an item up toNumberOfFramesthat has none. An item that has aFrameContentSequencekeeps it, item 1 included. Before this PR, the normalizer replaced theFrameContentSequenceof item 1.normalizeMultiframereplaces anullper-frame item up toNumberOfFrameswith an empty item, soPerFrameFunctionalGroupsSequence: [null, {}]does not give aTypeError.normalizeMultiframedoes not change items afterNumberOfFrames. The normalizer does not remove these items, and it does not add aFrameContentSequenceto them. This is the behaviour before this PR. The window guess skips anullitem afterNumberOfFrames, and the item staysnull.planePositionGroupgives each item its own copy of anImagePositionPatientarray. A value that is not an array goes through unchanged, the same as before fix(normalizers): normalize multiframe datasets missing functional groups (port of #603) #662.The doc comment of
normalizeMultiframerecords these rules. No copy ofnormalizeMultiframeorconvertToMultiframeis inpackages/. No spec indocs/specs/covers the normalizers, so this PR does not change a document.Note: the shape of a one-item shared array
Before this PR, the normalizer kept a one-item
SharedFunctionalGroupsSequencearray as an array. After this PR, the normalizer gives the item with the[0]andlengthaccessors, the same asnaturalizeDataset.SharedFunctionalGroupsSequence[0]gives the item, as before.SharedFunctionalGroupsSequence.Xnow also gives the value.Array.isArray(SharedFunctionalGroupsSequence)is nowfalse.Tests
The tests are in
test/segIncompleteMultiframe.test.js:NumberOfFrames8 gives 8 per-frame items, and two items do not share oneImagePositionPatientarray.ImagePositionPatientarray.PlaneOrientationSequence,PixelMeasuresSequence, andPixelValueTransformationSequence. These groups survive adenaturalizeDatasetandnaturalizeDatasetround trip. The shared group has the[0]accessor.FrameContentSequence. A new item gets aFrameContentSequencewith the correctInStackPositionNumber.[null, {}], withNumberOfFrames8, gives 8 items. The first items keep their positions, and each item has aFrameContentSequencewith the correctInStackPositionNumber.nullper-frame item afterNumberOfFramesdoes not throw, and the item staysnull..PixelMeasuresSequenceand[0]both work.NumberOfFrames1, so that the input is complete.Before the fix of
07f8324, the 3 new tests of that commit fail:Received: [].Expected length: 8,Received length: 3.TypeError: Cannot read properties of undefined (reading 'InStackPositionNumber').Before the fix of
83fdb5e, the test for an existingFrameContentSequencefails: the normalizer replaces the sequence of each item. Before07f8324, the round trip test fails, because the shared group is an empty array.Before the fix of
8223bec, 3 tests fail:nullitem afterNumberOfFrames:TypeErrorfromexpect(received).not.toThrow().expect(shared[0]).toBe(shared)givesReceived: undefined.expect(shared[0]).toBe(shared)givesReceived: undefined.When the
||= {}guard is removed, the[null, {}]case fails withTypeError: Cannot read properties of null (reading 'FrameContentSequence').After the fix:
npx jest test/segIncompleteMultiframe.test.js test/normalizers: 16 tests pass.npx jestafter the merge: 125 suites pass and 2 are skipped. 1461 tests pass and 11 are skipped.pnpm run buildandtest/bundle-size.test.jspass after the merge of1.0-betawith fix: byte order of binary value fields in Explicit VR Big Endian (port of #622) #663.dcmjs.jsis 1515056 bytes (ratio ×1.09435). This size is more than the ceiling ×1.094 of1.0-beta, so this PR sets the ceiling to ×1.095.dcmjs.es.jsis 1460580 bytes (ratio ×1.07600, ceiling ×1.076, no change). The comment intest/bundle-size.test.jsgives the same ratios.Known items for later
FrameContentSequencethat the normalizer adds has oneDimensionIndexValuesvalue (the frame number). TheDimensionIndexSequenceof an Enhanced input can have more dimensions. This PR does not change that behaviour.1.0-betawill go to separate issues: the frame time goes to the wrong frame after the sort ofconvertToMultiframe, and the window guess readsFrameVOILUTand notFrameVOILUTSequence.Links
4b0b844). Commit4b0b844does not have the fixes of S1, Q2, and N1.🤖 Generated with Claude Code