Skip to content

Commit 35628c1

Browse files
PaulHaxfloryst
authored andcommitted
fix(allocateImageFromChunks): port z spacing logic from ITK
1 parent 15b54ae commit 35628c1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/utils/allocateImageFromChunks.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ export function allocateImageFromChunks(sortedChunks: Chunk[]) {
117117

118118
image.setSpacing([1, 1, 1]);
119119
if (slices > 1 && imagePositionPatient && pixelSpacing) {
120-
const secondMeta = new Map(sortedChunks[1].metadata);
121-
const secondIPP = toVec(secondMeta.get(ImagePositionPatientTag));
122-
if (secondIPP) {
123-
const spacing = [...pixelSpacing, 1];
120+
const lastMeta = new Map(sortedChunks[sortedChunks.length - 1].metadata);
121+
const lastIPP = toVec(lastMeta.get(ImagePositionPatientTag));
122+
if (lastIPP) {
124123
// assumption: uniform Z spacing
125124
const zVec = vec3.create();
126125
const firstIPP = imagePositionPatient;
127-
vec3.sub(zVec, secondIPP as vec3, firstIPP as vec3);
128-
spacing[2] = vec3.len(zVec) || 1;
126+
vec3.sub(zVec, lastIPP as vec3, firstIPP as vec3);
127+
const zSpacing = vec3.len(zVec) / (sortedChunks.length - 1) || 1;
128+
const spacing = [...pixelSpacing, zSpacing];
129129
image.setSpacing(spacing);
130130
}
131131
}

0 commit comments

Comments
 (0)