Skip to content

Commit

Permalink
fix(segmentGroups): workaround direction matrix bug in writeImage
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Dec 29, 2023
1 parent 5e2bf30 commit 6ae16e8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/store/segmentGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ const writeImage = async (format: string, image: vtkImageData) => {
}
// copyImage so writeImage does not detach live data when passing to worker
const itkImage = copyImage(vtkITKHelper.convertVtkToItkImage(image));

// Transpose the direction matrix to fix bug in @itk-wasm/image-io.writeImage
// Remove when @itk-wasm/image-io version is above 0.5.0 https://github.com/InsightSoftwareConsortium/itk-wasm/commit/ad9ca85eedc47c9d3444cf36859569c529886bde
const oldDirection = [...itkImage.direction];
const { dimension } = itkImage.imageType;
for (let idx = 0; idx < dimension; ++idx) {
for (let idy = 0; idy < dimension; ++idy) {
itkImage.direction[idx + idy * dimension] =
oldDirection[idy + idx * dimension];
}
}

const result = await writeImageItk(null, itkImage, `image.${format}`);
return result.serializedImage.data;
};
Expand Down

0 comments on commit 6ae16e8

Please sign in to comment.