H5 to Tiff macro works on imagej but not on FIJI

Hey everyone.
My lab uses a hyperspectral microscope that works with physpec and produces H5 files. We have a macro for imageJ that converts there H5 files into tiff so that we can then analyze them (the importer doesn’t accept H5 for some reason), however, this macro only seems to work with imageJ and not with FIJI. It’s not a big deal but quite annoying having imageJ as a backup just for one plugin.
Would love some advice or help if anyone knows how to deal with something like that.
Thanks!

1 Like

Hey @Ron_Feiner,

would you mind sharing the macro and/or the error message? Might be easier to guess what’s not going right :wink: An example H5 file would also be very helpful so that we can try it out.

Merry Christmas :christmas_tree:

Cheers,
Robert

Hi Robert,
Thanks for taking the time to help out.
I am attaching the macro and a couple H5 files I grabbed last week.
let me know if you need anything else. h5 to tiff macro.rar (227.6 KB)

Ron

Hey @Ron_Feiner.

the macro file was empty… Could you please share it again?

Thanks!

Cheers,
Robert

Sorry about that.
Attaching it again and here is the text just in case:
"// Batch Convert

dir1 = getDirectory("Choose Source Directory ");
//format = getFormat();
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
cmd=“open” + “=[” + dir1+ list[i] + “]” +“1d 2d 3d”;
run(“HDF5…”, cmd);
saveAs(“Tiff”, dir2+list[i]);
close();
}

HDF2TiffMacro2.rar (358 Bytes)

Hi @Ron_Feiner,

it appears the HDF5 plugin has changed its user interface. I was able to fix your script by activating the macro recorder (Menu Plugins>Macros>Record) and checking the menus in Plugins>HDF5. It turned out that the “Scriptable load HDF5…” allows to work with your files. There two more issues: Firstly, you now need to know the path inside the HDF5 file where the image is located ("/Cube/Images"). Secondly, I got an error message because your two call to getDirectory started with “Choose”. This might be a bug in current ImageJ/Fiji. You can avoid it by changing the text in brakets.

// Batch Convert

dir1 = getDirectory("Source Directory ");
//format = getFormat();
dir2 = getDirectory("Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
	showProgress(i+1, list.length);
	cmd = "load=[C:/Users/rober/Downloads/h5 to tiff macro/16.h5] datasetnames=/Cube/Images nframes=1 nchannels=1";
	run("Scriptable load HDF5...", cmd);
	saveAs("Tiff", dir2+list[i]);
	close();
}

Could you please check the new script and confirm?

Cheers,
Robert

Hey Robert,

Sorry, I’m a bit out of depth here, not really my expertise. This macro was written by someone who isn’t in the lab anymore.

I tried replacing the script in the macro with the script you posted here but it throws an error.

I get that this is because the path you entered there is on your PC and not mine but I don’t know what path I should use there.

Thanks for the patience!
Ron

Hi @Ron_Feiner

sorry, my fault. Of course, it should be:

// Batch Convert

dir1 = getDirectory("Source Directory ");
//format = getFormat();
dir2 = getDirectory("Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
	showProgress(i+1, list.length);
	cmd = "load=[" + dir1+ list[i] + "] datasetnames=/Cube/Images nframes=1 nchannels=1";
	run("Scriptable load HDF5...", cmd);
	saveAs("Tiff", dir2+list[i]);
	close();
}

… as in your original script.

Cheers,
Robert

Hey Robert,
I tried running the macro and now I get this error message:

What could be the problem?
Thanks!

Hm, I’m not sure. Just for curiousity: Did you try with the images you uploaded here?

Furthermore, can you open the h5-file in question with Image > Import > HDF5 or any of the plugin in Plugins > HDF5?

Yes,
I’m able to open individual images by using
Plugins–>HDF5–>Load HDF5 file
and then choosing /Cube/Images in the data sets.
However, I can’t open multiple files so that I can then convert them to tiff to create a hyperstack (which is my ultimate goal and what the plugin is supposed to do)
Again thanks for the patience!!!

1 Like

Have you tried to run the macro recorder in combination with the menus in Plugins > HDF5? This is how I found out how to make it work …