Skip to content

Commit 19e8af5

Browse files
committed
fix(allocateImageFromChunks): support multi-frame
1 parent 1b953a0 commit 19e8af5

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/core/dicomTags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const tags: Tag[] = [
3232
{ name: 'SamplesPerPixel', tag: '0028|0002' },
3333
{ name: 'RescaleIntercept', tag: '0028|1052' },
3434
{ name: 'RescaleSlope', tag: '0028|1053' },
35+
{ name: 'NumberOfFrames', tag: '0028|0008' },
3536
];
3637

3738
export const TAG_TO_NAME = new Map(tags.map((t) => [t.tag, t.name]));

src/utils/allocateImageFromChunks.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
55
import { Vector3 } from '@kitware/vtk.js/types';
66
import { mat3, vec3 } from 'gl-matrix';
77
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
8+
import { vtkWarningMacro } from '@kitware/vtk.js/macros';
89

910
const ImagePositionPatientTag = NAME_TO_TAG.get('ImagePositionPatient')!;
1011
const ImageOrientationPatientTag = NAME_TO_TAG.get('ImageOrientationPatient')!;
@@ -16,6 +17,7 @@ const PixelRepresentationTag = NAME_TO_TAG.get('PixelRepresentation')!;
1617
const SamplesPerPixelTag = NAME_TO_TAG.get('SamplesPerPixel')!;
1718
const RescaleIntercept = NAME_TO_TAG.get('RescaleIntercept')!;
1819
const RescaleSlope = NAME_TO_TAG.get('RescaleSlope')!;
20+
const NumberOfFrames = NAME_TO_TAG.get('NumberOfFrames')!;
1921

2022
function toVec(s: Maybe<string>): number[] | null {
2123
if (!s?.length) return null;
@@ -84,8 +86,18 @@ export function allocateImageFromChunks(sortedChunks: Chunk[]) {
8486
const samplesPerPixel = Number(meta.get(SamplesPerPixelTag) ?? 1);
8587
const rescaleIntercept = Number(meta.get(RescaleIntercept) ?? 0);
8688
const rescaleSlope = Number(meta.get(RescaleSlope) ?? 1);
89+
const numberOfFrames = meta.has(NumberOfFrames)
90+
? Number(meta.get(NumberOfFrames))
91+
: null;
92+
93+
// If we have NumberOfFrames, chances are it's a multi-frame DICOM.
94+
if (numberOfFrames !== null && sortedChunks.length > 1) {
95+
vtkWarningMacro(
96+
'Found a multi-frame chunk in a group of chunks of size > 1'
97+
);
98+
}
8799

88-
const slices = sortedChunks.length;
100+
const slices = numberOfFrames === null ? sortedChunks.length : numberOfFrames;
89101
const TypedArrayCtor = getTypedArrayConstructor(
90102
bitsStored,
91103
pixelRepresentation,

0 commit comments

Comments
 (0)