Unable to Read MHD Files with metaReadImage

Hello
I’m encountering issues when trying to read MHD files using the metaReadImage method from ITK-Wasm. I’ve tried multiple approaches, but I cannot successfully load an MHD/ZRAW file. Additionally, the official online example also fails and returns an error that I am unable to interpret.

https://insightsoftwareconsortium.github.io/ITK-Wasm/image-io/ts/app/?functionName=readImage

I observed two distinct errors depending on how I attempt to read the file.

Case 1: “Cannot open data file” Error

Steps to Reproduce

  1. Select an .mhd file along with its corresponding .zraw file.
  2. Attempt to load the image using:
    const { image } = await metaReadImage(mhdFile);
    
  3. The following error appears in the console:

Error Message

MetaImage: Read: Cannot open data file
Exception while running pipeline
stderr: MetaImage: Read: Cannot open data file
Build module in Debug mode for exception message information.

Expected Behavior
The file should load correctly without failing to open the data file.

Case 2: “ErrnoError: 28” Error

Steps to Reproduce

  1. Select an .mhd file along with its corresponding .zraw file.
  2. Attempt to load the image using:
    const { image } = await metaReadImage([mhdFile, rawFile]);
    
  3. The following error appears in the console:

Error Message

Error reading MetaImage files: Object { name: "ErrnoError", errno: 28 }
const handleFileChange = async (event) => {
  const files = event.target.files;
  let mhdFile, rawFile;
  
  for (const file of files) {
    const name = file.name.toLowerCase();
    if (name.endsWith('.mhd')) {
      mhdFile = file;
    } else if (name.endsWith('.raw') || name.endsWith('.zraw')) {
      rawFile = file;
    }
  }

  try {
    console.log('Loaded MetaImage files:', mhdFile, rawFile);

    // Case 1
    const { image } = await metaReadImage(mhdFile);

    // Case 2
    // const { image } = await metaReadImage([mhdFile, rawFile]);

    setItkImage(image);
  } catch (error) {
    console.error('Error reading MetaImage files:', error);
  }
};

Would appreciate any guidance on resolving these issues! Thanks.

If you can use .mha (single file) instead of .mhd (header + data file), that will probably solve your problem.

@matt.mccormick and @jadh4v might have some thoughts to share.

Hi,

A function could be added to the ITK-Wasm image-io package that takes a .mhd and .raw files and produces a single .mha file.