Problem opening Ilastik .h5 file in Matlab

Hi, I’m a new user of Ilastik. I’m trying to open Ilastik .h5 probability maps in Matlab. I was successful with one file, but when I tried again using the same code and file type, but for a different image, I get an error message saying that the file cannot be found. I checked the export settings in Ilastik before exporting, and it says the dataset is “exported_data,” which is what’s in the code, so I’m very confused. I’ve checked the names of the files too.

Both files were imported to Ilastik from ImageJ and I’m confident I did the same steps for both. The only thing I changed in the code was the name of the file. Does anyone have any advice?

Here’s the code for the first (successfull) and second (unsuccessful) attempts:
First try:

ilastik_filename = ‘MAX_Series007_SM2_Probabilities.h5’; % ilastik prediction map here

ilastik_file = h5read(ilastik_filename,’/exported_data/’); % exported data is the “folder” in Ilastik project where the data is stored. Don’t change this.

pred = squeeze(ilastik_file(2,:,:,:)); % Originally 4D file, we want 3D
pred = permute(pred,[2,1,3]); % prevent the Ilastik axis swap by fixing them here

figure
imshow(sum(pred,3),)
title(‘Ilastik prediction map, z-projection’)

Second try:

ilastik_filename = ‘HidGFP_HFD8D_3_Probabilities.h5’; % ilastik prediction map here

ilastik_file = h5read(ilastik_filename,’/exported_data/’); % exported data is the “folder” in Ilastik project where the data is stored. Don’t change this.
pred = squeeze(ilastik_file(2,:,:,:)); % Originally 4D file, we want 3D
pred = permute(pred,[2,1,3]); % prevent the Ilastik axis swap by fixing them here

figure
imshow(sum(pred,3),)
title(‘Ilastik prediction map, z-projection’)

Hi Cait,
you provide filenames without full path and the most sensible explanation that your second file is in a different folder. Try to put the full path to the second h5 file as for example
ilastik_filename = 'c:\ilastik\dataset1\HidGFP_HFD8D_3_Probabilities.h5';

You can also try to check opening of both files with MIB under Matlab.

1 Like

Hello @Cait,

welcome to the image.sc forum!!

Just a quick tip in the beginning: The posts in image.sc support the Markdown syntax. With this you can e.g. make code blocks look nicer by enclosing them in appropriate tags. In order to highlight you’re matlab code, you’d put it into these tags:

```matlab
your code
here
```

Disclaimer: I do not have access to Matlab, but worked with it eons ago. I’m only expanding a tiny bit on @Ilya_Belevich answer.

Per default ilastik will export the result to an hdf5 file with the dataset exported_data. Minor comment to your code: from the h5read documentation it looks like they omit the trailing forward slash (/) for the dataset name. But it seems to work anyways.

In order to debug your problem a bit, you could try using h5disp with the second file name just to make sure it is there, and also the internal dataset is there.

Cheers

1 Like