BodenmillerGroup / steinbock

A toolkit for processing multiplexed tissue images
https://bodenmillergroup.github.io/steinbock
MIT License
49 stars 14 forks source link

Adding manual crops for Ilastik training #120

Closed luglilab closed 2 years ago

luglilab commented 2 years ago

How should one make a manual crop of the ilastik images to add to the training data set in Ilastik? The steinbock pipeline generates both Ilastik images and crops as an .h5 file with 3 dimensions (cyx). When importing the .h5 files in Fiji with the Ilastik plugin, it automatically imports it in 5 dimensions (tzyxc). Manual cropping and saving also generates a 5-dimension h5 file. Mixing cyx and tzyxc files in Ilastik generates an error during batch processing. How should we solve this?

jwindhager commented 2 years ago

Hi @luglilab, thanks for reaching out! To be perfectly honest, when building steinbock, we did not have the use case of manual crops in mind, but this should certainly be supported. Personally, I was not aware of the Ilastik Fiji plugin or any related requirements regarding the HDF5 format/dimension order. Could you elaborate a bit on your desired workflow?

If I understand correctly, you would open and crop images in Fiji, followed by (directly?) importing them into the Ilastik project using the From FIJI to Ilastik workflow? Here, the problem does not seem to be the import into Ilastik (afaik, Ilastik merely "assigns labels" to the different dimensions), but that the .h5 files exported by the Fiji plugin in your case seem to contain 5 dimensions. Looking at the link above, I read the following:

It will warn you to be careful with the axes order, but don't worry, if you get it wrong you can still correct it on import in ilastik.

This seems to suggest that the Fiji plugin exports the image dimensions "as is", i.e. as the image is loaded in Fiji. Could you maybe try to reshape the image in Fiji to have a CYX dimension order before the export? and then see, where it breaks:

  1. at the export from Fiji (check e.g. in code or using the HDFView software)
  2. at the import in Ilastik (check by simply importing the CYX .h5 file in Ilastik)

If the problem is indeed point (2), I'd be happy to adapt the steinbock Ilastik HDF5 specifications for compatibility with the Ilastik Fiji plugin in a future release. However, this would mean a breaking change in steinbock, rendering previously trained classifiers unusable with new steinbock releases, so it would be great if this could be avoided.

luglilab commented 2 years ago

Hi @jwindhager, we would like to keep the random crops in the Ilastik project file and additionally add manually generated crops to improve the training of the classifier. The problem was generated by the Ilastik plugin in Fiji, which only allows exporting as tzyxc. But we now have resolved the issue, indeed in the Ilastik software there is an option to change the HDF5 axis order. So no need to make changes to steinbock.

jwindhager commented 2 years ago

Thanks for reporting back @luglilab! Closing

sdhcdifhwen commented 10 months ago

Hi @jwindhager, we would like to keep the random crops in the Ilastik project file and additionally add manually generated crops to improve the training of the classifier. The problem was generated by the Ilastik plugin in Fiji, which only allows exporting as tzyxc. But we now have resolved the issue, indeed in the Ilastik software there is an option to change the HDF5 axis order. So no need to make changes to steinbock.

Hi @luglilab , I met the same question with you. Could you kindly tell me when I can change the dimensions in Ilastik? At the import in Ilastik , if I change to cyx, it would warn that dataset has 5 dimensions, so I need to provide that many axes keys. And I can't save it. Thank you very much.