From 6ae16e8ff42c0d80259589486da235d92ff28ab7 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 8 Dec 2023 16:18:37 -0500 Subject: [PATCH] fix(segmentGroups): workaround direction matrix bug in writeImage --- src/store/segmentGroups.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/store/segmentGroups.ts b/src/store/segmentGroups.ts index 20914dbab..fb9929d98 100644 --- a/src/store/segmentGroups.ts +++ b/src/store/segmentGroups.ts @@ -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; };