diff --git a/src/dicom/core/collections/multiframeGeometry.ts b/src/dicom/core/collections/multiframeGeometry.ts index 94f46fd03..0bc2c7ea9 100644 --- a/src/dicom/core/collections/multiframeGeometry.ts +++ b/src/dicom/core/collections/multiframeGeometry.ts @@ -41,7 +41,7 @@ const singleSpatialStack = (groups: DicomDataset[]) => * Patient-space frames keep their stored pixel order. The third direction * follows the positions, which can run opposite the row/column cross product. * Ophthalmic scan-line coordinates require a separate calibrated localizer; - * optical SliceThickness cannot substitute for their separation. + * SliceThickness cannot place frames, so it is only a spacing fallback. */ export function multiframeGeometry(metadata: DicomDataset, count: number) { const groups = perFrameGroups(metadata); diff --git a/src/dicom/core/volume/__tests__/frameGeometry.spec.ts b/src/dicom/core/volume/__tests__/frameGeometry.spec.ts index dd27ba4ec..94fcaffc3 100644 --- a/src/dicom/core/volume/__tests__/frameGeometry.spec.ts +++ b/src/dicom/core/volume/__tests__/frameGeometry.spec.ts @@ -185,7 +185,7 @@ describe('enhanced volume Functional Groups', () => { }); }); - it('reads OCT in-plane calibration without using optical depth of field as frame separation', () => { + it('separates unpositioned OCT frames by the shared SliceThickness', () => { const metadata = enhanced( groups([ sequence('00289110', [ @@ -197,7 +197,9 @@ describe('enhanced volume Functional Groups', () => { ]), [groups([]), groups([])] ); - expect(allocate(metadata).spacing).toEqual([0.01174168, 0.001955034, 1]); + expect(allocate(metadata).spacing).toEqual([ + 0.01174168, 0.001955034, 0.002, + ]); }); it('reports shared-plane temporal frames as irregular', () => { diff --git a/src/dicom/core/volume/__tests__/volumeLayout.spec.ts b/src/dicom/core/volume/__tests__/volumeLayout.spec.ts index 0bd76656f..73db25680 100644 --- a/src/dicom/core/volume/__tests__/volumeLayout.spec.ts +++ b/src/dicom/core/volume/__tests__/volumeLayout.spec.ts @@ -173,4 +173,35 @@ describe('volumeLayout', () => { expect(spacingOf(layout)[2]).toBe(2.5); }); + + it('falls back to SliceThickness when nothing else spaces the frames', () => { + const layout = layoutOf( + [ + volumeSource({ + [Tags.NumberOfFrames]: '32', + [Tags.ImagePositionPatient]: '', + [Tags.SliceThickness]: '0.25', + }), + ], + AXIAL + ); + + expect(spacingOf(layout)[2]).toBe(0.25); + }); + + it('prefers SpacingBetweenSlices over SliceThickness', () => { + const layout = layoutOf( + [ + volumeSource({ + [Tags.NumberOfFrames]: '32', + [Tags.ImagePositionPatient]: '', + [Tags.SpacingBetweenSlices]: '0.5', + [Tags.SliceThickness]: '0.25', + }), + ], + AXIAL + ); + + expect(spacingOf(layout)[2]).toBe(0.5); + }); }); diff --git a/src/dicom/core/volume/volumeLayout.ts b/src/dicom/core/volume/volumeLayout.ts index 4c427c449..b559770f4 100644 --- a/src/dicom/core/volume/volumeLayout.ts +++ b/src/dicom/core/volume/volumeLayout.ts @@ -4,10 +4,10 @@ import { Tags } from '../metadata/dicomTags'; import { readGeometryFacts, sliceNormalOf } from '../collections/instanceFacts'; import type { Reconstruction } from '../collections/reconstructVolume'; import { readDatasetDetails } from '../collections/datasetDetails'; -import { readPixelSpacing, spacingOr1 } from '../metadata/spatialMetadata'; +import { readPixelSpacing } from '../metadata/spatialMetadata'; import { getFrameTag } from '../metadata/functionalGroups'; import { frameCount } from '../pixels/pixelDecoder'; -import { numberOr } from '../utils'; +import { numberOr, trimDicomPadding } from '../utils'; import { nmGeometry } from './nmGeometry'; import { getVolumeBufferType, instancePixelFormats } from './pixelFormat'; import { applyUltrasoundSpacing } from './ultrasoundSpacing'; @@ -68,6 +68,13 @@ function allocationShape(sources: readonly VolumeSource[]) { }; } +// SliceThickness is only a stand-in for the gap: it can differ from it, but +// many enhanced OCT files declare nothing else. +const declaredSliceSpacing = (dataset: DicomDataset) => + [Tags.SpacingBetweenSlices, Tags.SliceThickness] + .map((tag) => Number(trimDicomPadding(getFrameTag(dataset, tag) ?? ''))) + .find(isPositiveFiniteNumber) ?? 1; + function allocationSpacing( dataset: DicomDataset, { reconstruction }: ReturnType @@ -75,7 +82,7 @@ function allocationSpacing( const sliceSpacing = reconstruction.sliceSpacing ?? 0; const z = isPositiveFiniteNumber(sliceSpacing) ? sliceSpacing - : spacingOr1(getFrameTag(dataset, Tags.SpacingBetweenSlices)); + : declaredSliceSpacing(dataset); return [...readPixelSpacing(dataset), z]; }