Kitware/VolView

itk reader fail to detect image type ?

lchauvin opened this issue · 5 comments

Hello,

I updated VolView code to the latest (main branch), and I'm not able to load minc files now.

I did a bit of debugging, and the issue seems to be in the function itkReader in src/io/readers.ts.

Here the function readImage seems not able to load it. I tried to replace it with mincReadImage as a test, and it works.

It seems for some reason, readImage is not able to identify the image as minc, although, I checked the extension is supported.

When trying to read a minc image, I'm getting this error:

application/vnd.unknown.minc

loggers.ts:13 TypeError: Cannot read properties of undefined (reading '0')
    at readImage (@itk-wasm_image-io.js?v=9a3488c0:2031:30)
    at async itkReader (readers.ts:21:32)
    at async importSingleFile (importSingleFile.ts:31:22)
    at async invokeHandler (pipeline.ts:226:20

The error seems to happen here in itk-wasm_image-io.js:

  const readerWriter = image_io_index_default.get(io);
  const reader = readerWriter[0];

on the line const reader = readerWriter[0];

Here is the file I'm trying to load when printing file in itkReader:

File {name: 't2w.mnc', lastModified: 1716909043156, lastModifiedDate: Tue May 28 2024 11:10:43 GMT-0400 (Eastern Daylight Time), webkitRelativePath: '', size: 15747302, …}
lastModified: 1716909043156
lastModifiedDate: Tue May 28 2024 11:10:43 GMT-0400 (Eastern Daylight Time) {}
name: "t2w.mnc"
size: 15747302
type: ""
webkitRelativePath: ""
[[Prototype]]: File

I tried with a Nifti image, and it works, but I don't see any difference, except for the file type:

application/vnd.unknown.nifti-1

File {name: 'MR_Gd.nii', lastModified: 1716909309256, lastModifiedDate: Tue May 28 2024 11:15:09 GMT-0400 (Eastern Daylight Time), webkitRelativePath: '', size: 4765024, …}
lastModified: 1716909309256
lastModifiedDate: Tue May 28 2024 11:15:09 GMT-0400 (Eastern Daylight Time) {}
name: "MR_Gd.nii"
size: 4765024
type: ""
webkitRelativePath: ""
[[Prototype]]: File

After some further investigation, the problem is that readImage is sometimes using the extension to find the reader. The MINC extension is .mnc or .mnc.gz, but in the list of readers, it is listed as minc, so it doesn't find the readers:

// node_modules/@itk-wasm/image-io/dist/image-io-index.js
var imageIoIndex = /* @__PURE__ */ new Map([
  ["png", [png_read_image_default, png_write_image_default]],
  ["meta", [meta_read_image_default, meta_write_image_default]],
  ["tiff", [tiff_read_image_default, tiff_write_image_default]],
  ["nifti", [nifti_read_image_default, nifti_write_image_default]],
  ["jpeg", [jpeg_read_image_default, jpeg_write_image_default]],
  ["nrrd", [nrrd_read_image_default, nrrd_write_image_default]],
  ["vtk", [vtk_read_image_default, vtk_write_image_default]],
  ["bmp", [bmp_read_image_default, bmp_write_image_default]],
  ["hdf5", [hdf5_read_image_default, hdf5_write_image_default]],
  ["minc", [minc_read_image_default, minc_write_image_default]],
  ["mrc", [mrc_read_image_default, mrc_write_image_default]],
  ["lsm", [lsm_read_image_default, lsm_write_image_default]],
  ["mgh", [mgh_read_image_default, mgh_write_image_default]],
  ["bioRad", [bio_rad_read_image_default, bio_rad_write_image_default]],
  ["gipl", [gipl_read_image_default, gipl_write_image_default]],
  ["geAdw", [ge_adw_read_image_default, ge_adw_write_image_default]],
  ["ge4", [ge4_read_image_default, ge4_write_image_default]],
  ["ge5", [ge5_read_image_default, ge5_write_image_default]],
  ["gdcm", [gdcm_read_image_default, gdcm_write_image_default]],
  ["scanco", [scanco_read_image_default, scanco_write_image_default]],
  ["fdf", [fdf_read_image_default, null]],
  ["wasm", [wasm_read_image_default, wasm_write_image_default]],
  ["wasmZstd", [wasm_zstd_read_image_default, wasm_zstd_write_image_default]]
]);

It should be mnc, as listed here:

// node_modules/@itk-wasm/image-io/dist/extension-to-image-io.js
var extensionToImageIo = /* @__PURE__ */ new Map([
  ["bmp", "bmp"],
  ["dcm", "gdcm"],
  ["gipl", "gipl"],
  ["gipl.gz", "gipl"],
  ["hdf5", "hdf5"],
  ["jpg", "jpeg"],
  ["jpeg", "jpeg"],
  ["iwi", "wasm"],
  ["iwi.cbor", "wasm"],
  ["iwi.cbor.zst", "wasmZstd"],
  ["lsm", "lsm"],
  ["mnc", "mnc"],
  ["mnc.gz", "mnc"],
  ["mnc2", "mnc"],
  ["mgh", "mgh"],
  ["mgz", "mgh"],
  ["mgh.gz", "mgh"],
  ["mha", "meta"],
  ["mhd", "meta"],
  ["mrc", "mrc"],
  ["nia", "nifti"],
  ["nii", "nifti"],
  ["nii.gz", "nifti"],
  ["hdr", "nifti"],
  ["nrrd", "nrrd"],
  ["nhdr", "nrrd"],
  ["png", "png"],
  ["pic", "bioRad"],
  ["tif", "tiff"],
  ["tiff", "tiff"],
  ["vtk", "vtk"],
  ["isq", "scanco"],
  ["aim", "scanco"],
  ["fdf", "fdf"]
]);

Nice find. If you open an issue and offer to write a PR here: https://github.com/InsightSoftwareConsortium/itk-wasm might have a clean fix in a week or so.