Repository navigation
fix(seg): save the segment of an overlap labelmap layer under its own segment number #6352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wayfarer3130
merged 17 commits into
OHIF:master
from
TFRadicalImaging:fix/seg-export-overlap-layer-segment-index
Oct 15, 2026
+662
−197
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fe408d8
fix(seg): save the segment of an overlap labelmap layer under its own…
TFRadicalImaging 7696586
fix(seg): map overlap layer labels from segment bindings without full…
wayfarer3130 e1560c0
fix(seg): keep unbound label values like the renderer, and tidy the r…
wayfarer3130 5406f67
test(seg): add unit tests for the labelmap layer remap
wayfarer3130 766b017
docs(seg): note the follow-ups for cornerstone3D#2988 in comments
wayfarer3130 2ab0e90
fix(seg): enable the SEG export when only an overlap layer has data
wayfarer3130 278cdb8
Merge branch 'master' into fix/seg-export-overlap-layer-segment-index
wayfarer3130 3f8b44d
fix(seg): export with the label map of each layer, and drop label val…
TFRadicalImaging 279ba71
perf(segmentation): scan the labelmap voxels for the export option on…
TFRadicalImaging 7cac7fe
test(seg): anchor the @ohif module mappers of the jest config
TFRadicalImaging b94669e
test(seg): move the segment to an overlap layer with the cornerstone3…
TFRadicalImaging ef069aa
chore(deps): update cornerstone3D to 5.12.0
wayfarer3130 040e3f2
fix(seg): export the label map of each layer with the SEG adapter, an…
wayfarer3130 d3418b8
fix(segmentation): do not keep the voxel scan result while a labelmap…
wayfarer3130 7f8896b
test(seg): move the segment to an overlap layer with the cornerstone3…
wayfarer3130 a53fbc3
fix(segmentation): scan the top-level image ids when the only labelma…
TFRadicalImaging 8db99c8
refactor(segmentation): share the single-layer export source between …
wayfarer3130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const base = require('../../jest.config.base.js'); | ||
|
|
||
| module.exports = { | ||
| ...base, | ||
| moduleNameMapper: { | ||
| ...base.moduleNameMapper, | ||
| // Deep imports already name `src`, so they must be matched before the | ||
| // catch-all below appends a second one. | ||
| '^@ohif/([^/]+)/src/(.*)$': '<rootDir>/../../platform/$1/src/$2', | ||
| '^@ohif/([^/]+)$': '<rootDir>/../../platform/$1/src', | ||
| }, | ||
| }; |
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
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
35 changes: 35 additions & 0 deletions
35
extensions/cornerstone-dicom-seg/src/utils/labelmapLayerSegmentIndices.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { | ||
| getExportedLabelValues, | ||
| getExportLabelToSegmentIndex, | ||
| } from './labelmapLayerSegmentIndices'; | ||
|
|
||
| // Segment 2 is in a private layer under label value 1. | ||
| const privateLabelToSegmentIndex = { 1: 2 }; | ||
|
|
||
| describe('getExportedLabelValues', () => { | ||
| it('keeps every label value when the layer has no label map', () => { | ||
| expect(getExportedLabelValues(new Uint8Array([0, 1, 3, 3]))).toEqual([1, 3]); | ||
| }); | ||
|
|
||
| it('does not export a label value that has no segment, and reports it', () => { | ||
| const unboundLabels = new Set<number>(); | ||
|
|
||
| const labelValues = getExportedLabelValues( | ||
| new Uint8Array([1, 5, 5]), | ||
| privateLabelToSegmentIndex, | ||
| unboundLabels | ||
| ); | ||
|
|
||
| expect(labelValues).toEqual([1]); | ||
| expect(Array.from(unboundLabels)).toEqual([5]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getExportLabelToSegmentIndex', () => { | ||
| it('maps a label value that has no segment to 0, so the adapter does not export it', () => { | ||
| expect(getExportLabelToSegmentIndex(privateLabelToSegmentIndex, new Set([5]))).toEqual({ | ||
| 1: 2, | ||
| 5: 0, | ||
| }); | ||
| }); | ||
| }); |
62 changes: 62 additions & 0 deletions
62
extensions/cornerstone-dicom-seg/src/utils/labelmapLayerSegmentIndices.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** The map from a label value in the voxels of a labelmap layer to the segment index. */ | ||
| export type LabelToSegmentIndex = { [labelValue: number]: number }; | ||
|
|
||
| /** | ||
| * Gets the label values of one labelmap slice that the SEG export includes, in | ||
| * one pass. The result is the `segmentsOnLabelmap` of a labelmap2D, which the | ||
| * SEG adapter reads as label values. | ||
| * | ||
| * cs3D stores a segment in a private overlap layer under a label value that is | ||
| * not its segment index (usually 1), and keeps the map in `labelToSegmentIndex` | ||
| * of each layer. A label value that has no entry in that map belongs to no | ||
| * segment: it is not returned, and it is added to `unboundLabels`. Without a | ||
| * map, every label value is its own segment index. | ||
| * | ||
| * @param pixelData - The voxel values of the labelmap slice. | ||
| * @param labelToSegmentIndex - The label map of the layer, or undefined. | ||
| * @param unboundLabels - Gets each label value that has no entry in the map. | ||
| */ | ||
| export function getExportedLabelValues( | ||
| pixelData, | ||
| labelToSegmentIndex?: LabelToSegmentIndex, | ||
| unboundLabels?: Set<number> | ||
| ): number[] { | ||
| const labelValues = new Set<number>(); | ||
| for (let i = 0; i < pixelData.length; i++) { | ||
| const labelValue = pixelData[i]; | ||
| if (labelValue !== 0) { | ||
| labelValues.add(labelValue); | ||
| } | ||
| } | ||
| if (!labelToSegmentIndex) { | ||
| return Array.from(labelValues); | ||
| } | ||
| return Array.from(labelValues).filter(labelValue => { | ||
| if (labelToSegmentIndex[labelValue]) { | ||
| return true; | ||
| } | ||
| unboundLabels?.add(labelValue); | ||
| return false; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the `labelToSegmentIndex` of a labelmap3D for the SEG adapter. | ||
| * | ||
| * The adapter reads a label value that is not in the map as its own segment | ||
| * index. The export must not include a label value that has no segment, so the | ||
| * map gives segment index 0 (no segment) to each such label value. | ||
| */ | ||
| export function getExportLabelToSegmentIndex( | ||
| labelToSegmentIndex: LabelToSegmentIndex | undefined, | ||
| unboundLabels: Set<number> | ||
| ): LabelToSegmentIndex | undefined { | ||
| if (!labelToSegmentIndex) { | ||
| return undefined; | ||
| } | ||
| const exportMap = { ...labelToSegmentIndex }; | ||
| unboundLabels.forEach(labelValue => { | ||
| exportMap[labelValue] = 0; | ||
| }); | ||
| return exportMap; | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.