Skip to content

Commit

Permalink
fix(allocateImageFromChunks): support multi-frame
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Aug 8, 2024
1 parent 1b953a0 commit 19e8af5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/dicomTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const tags: Tag[] = [
{ name: 'SamplesPerPixel', tag: '0028|0002' },
{ name: 'RescaleIntercept', tag: '0028|1052' },
{ name: 'RescaleSlope', tag: '0028|1053' },
{ name: 'NumberOfFrames', tag: '0028|0008' },
];

export const TAG_TO_NAME = new Map(tags.map((t) => [t.tag, t.name]));
Expand Down
14 changes: 13 additions & 1 deletion src/utils/allocateImageFromChunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
import { Vector3 } from '@kitware/vtk.js/types';
import { mat3, vec3 } from 'gl-matrix';
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
import { vtkWarningMacro } from '@kitware/vtk.js/macros';

const ImagePositionPatientTag = NAME_TO_TAG.get('ImagePositionPatient')!;
const ImageOrientationPatientTag = NAME_TO_TAG.get('ImageOrientationPatient')!;
Expand All @@ -16,6 +17,7 @@ const PixelRepresentationTag = NAME_TO_TAG.get('PixelRepresentation')!;
const SamplesPerPixelTag = NAME_TO_TAG.get('SamplesPerPixel')!;
const RescaleIntercept = NAME_TO_TAG.get('RescaleIntercept')!;
const RescaleSlope = NAME_TO_TAG.get('RescaleSlope')!;
const NumberOfFrames = NAME_TO_TAG.get('NumberOfFrames')!;

function toVec(s: Maybe<string>): number[] | null {
if (!s?.length) return null;
Expand Down Expand Up @@ -84,8 +86,18 @@ export function allocateImageFromChunks(sortedChunks: Chunk[]) {
const samplesPerPixel = Number(meta.get(SamplesPerPixelTag) ?? 1);
const rescaleIntercept = Number(meta.get(RescaleIntercept) ?? 0);
const rescaleSlope = Number(meta.get(RescaleSlope) ?? 1);
const numberOfFrames = meta.has(NumberOfFrames)
? Number(meta.get(NumberOfFrames))
: null;

// If we have NumberOfFrames, chances are it's a multi-frame DICOM.
if (numberOfFrames !== null && sortedChunks.length > 1) {
vtkWarningMacro(
'Found a multi-frame chunk in a group of chunks of size > 1'
);
}

const slices = sortedChunks.length;
const slices = numberOfFrames === null ? sortedChunks.length : numberOfFrames;
const TypedArrayCtor = getTypedArrayConstructor(
bitsStored,
pixelRepresentation,
Expand Down

0 comments on commit 19e8af5

Please sign in to comment.