Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dicom/core/collections/multiframeGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/dicom/core/volume/__tests__/frameGeometry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -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', () => {
Expand Down
31 changes: 31 additions & 0 deletions src/dicom/core/volume/__tests__/volumeLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
13 changes: 10 additions & 3 deletions src/dicom/core/volume/volumeLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -68,14 +68,21 @@ 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<typeof allocationGeometry>
) {
const sliceSpacing = reconstruction.sliceSpacing ?? 0;
const z = isPositiveFiniteNumber(sliceSpacing)
? sliceSpacing
: spacingOr1(getFrameTag(dataset, Tags.SpacingBetweenSlices));
: declaredSliceSpacing(dataset);
return [...readPixelSpacing(dataset), z];
}

Expand Down
Loading