# Unable to Read MHD Files with metaReadImage

**URL:** <https://discourse.itk.org/t/unable-to-read-mhd-files-with-metareadimage/7447>\
**Category:** Beginner Questions\
**Tags:** itk, image, itk-wasm\
**Created:** [February 28, 2025, 10:45am UTC](https://discourse.itk.org/t/unable-to-read-mhd-files-with-metareadimage/7447 "2025-02-28T10:45:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GMrrc](https://discourse.itk.org/user_avatar/discourse.itk.org/gmrrc/32/4478_2.png) [@GMrrc](https://discourse.itk.org/u/GMrrc)\
**Post date:** [February 28, 2025, 10:45am UTC](https://discourse.itk.org/t/unable-to-read-mhd-files-with-metareadimage/7447/1 "2025-02-28T10:45:23Z")

</div>

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](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:

```javascript
const { image } = await metaReadImage(mhdFile);

```

3. The following error appears in the console:

Error Message

```auto
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:

```javascript
const { image } = await metaReadImage([mhdFile, rawFile]);

```

3. The following error appears in the console:

Error Message

```auto
Error reading MetaImage files: Object { name: "ErrnoError", errno: 28 }

```

```javascript
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.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [February 28, 2025, 2:29pm UTC](https://discourse.itk.org/t/unable-to-read-mhd-files-with-metareadimage/7447/2 "2025-02-28T14:29:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [February 28, 2025, 9:34pm UTC](https://discourse.itk.org/t/unable-to-read-mhd-files-with-metareadimage/7447/3 "2025-02-28T21:34:14Z")

</div>

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.
