Cannot export pixel classification results in ilastik4ij using macro

I’m trying to use ilastik as a replacement for thresholding in ImageJ. For some reason, I couldn’t address the segmentation results in ImageJ to export it. The example provided on ilastik4ij GitHub doesn’t work either. The results is also stored in a temporary folder, so I couldn’t use selectWindow().

Sample image and/or code

//Perform segmentation
selectWindow("MAX_C2-" + imageTitle);
close("\\Others");
ilastik_classify_args = "projectfilename=[/Volumes/Flat full z stacks.ilp] inputimage=[" + "MAX_C2-" + imageTitle + "] saveonly=false pixelclassificationtype=Segmentation";
run("Run Pixel Classification Prediction", ilastik_classify_args);
//Export .h5 and reimport, save as .tif, then import that.
ilastik_export_args = "select=[" + output + "binary_" + imageTitle + ".h5] " + "datasetname=data compressionlevel=0";
run("Export HDF5", ilastik_export_args);

Here’s the console output:

[INFO] Running ilastik headless command:
[INFO] [/Applications/ilastik-1.4.0b8-OSX.app/Contents/MacOS/ilastik, --headless, --project=/Volumes/INHIST2020-Q3344/2021-01-06 ilastik test/ilastik project/Flat full z stacks.ilp, --output_format=hdf5, --output_axis_order=tzyxc, --input_axes=tzyxc, --readonly, --output_internal_path=exported_data, --input_axes=tzyxc, --export_source=Simple Segmentation, --raw_data=/var/folders/tg/3hdw5s3s0hg4crdsqt5n2ywc0000gq/T/ilastik4j4907492669311425173_in_raw.h5, --output_filename_format=/var/folders/tg/3hdw5s3s0hg4crdsqt5n2ywc0000gq/T/ilastik4j9133301468090674222_out.h5]
[INFO] INFO ilastik.app: config file location: <none>
[INFO] INFO ilastik.app: Starting ilastik from "/Applications/ilastik-1.4.0b8-OSX.app/Contents/ilastik-release/ilastik-meta".
[INFO] Starting ilastik from "/Applications/ilastik-1.4.0b8-OSX.app/Contents/ilastik-release/ilastik-meta".
[INFO] INFO ilastik.app: Configuring lazyflow RAM limit to 4.0GiB
[INFO] INFO lazyflow.utility.memory: Available memory set to 4.0GiB
[ERROR] WARNING 2021-01-07 13:14:10,756 opConservationTracking 5168 4412732864 Could not find any ILP solver
[ERROR] WARNING 2021-01-07 13:14:10,783 opStructuredTracking 5168 4412732864 Could not find any ILP solver
[ERROR] WARNING 2021-01-07 13:14:10,792 structuredTrackingWorkflow 5168 4412732864 Could not find any learning solver. Tracking will use flow-based solver (DPCT). Learning for tracking will be disabled!
[INFO] INFO ilastik.shell.projectManager: Opening Project: /Volumes/INHIST2020-Q3344/2021-01-06 ilastik test/ilastik project/Flat full z stacks.ilp
[ERROR] WARNING opSimpleBlockedArrayCache.py(43): FutureWarning: Conversion of the second argument of issubdtype from `dtype` to `np.generic` is deprecated. In future, it will be treated as `np.object_ == np.dtype(dtype).type`.
[ERROR] WARNING opSlicedBlockedArrayCache.py(141): FutureWarning: Conversion of the second argument of issubdtype from `dtype` to `np.generic` is deprecated. In future, it will be treated as `np.object_ == np.dtype(dtype).type`.
[INFO] INFO ilastik.workflows.pixelClassification.pixelClassificationWorkflow: Beginning Batch Processing
[INFO] INFO ilastik.applets.dataSelection.dataSelectionApplet: Forcing input axes to [t z y x c, t z y x c]
[INFO] INFO ilastik.applets.batchProcessing.batchProcessingApplet: Exporting to /var/folders/tg/3hdw5s3s0hg4crdsqt5n2ywc0000gq/T/ilastik4j9133301468090674222_out.h5/exported_data
[INFO] INFO lazyflow.operators.ioOperators.ioOperators.OpH5N5WriterBigDataset: Data shape: (1, 1, 1040, 1388, 1)
[INFO] INFO lazyflow.utility.bigRequestStreamer: Estimated RAM usage per pixel is 68.0B * safety factor (2.0)
[INFO] INFO lazyflow.utility.bigRequestStreamer: determining blockshape assuming available_ram is 3.0GiB, split between 4 threads
[INFO] INFO lazyflow.utility.bigRequestStreamer: Chose blockshape: (1, 1, 1040, 1388, 2)
[INFO] INFO lazyflow.utility.bigRequestStreamer: Estimated RAM usage per block is 187.2MiB
[ERROR] WARNING arraytypes.py(1263): FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
[ERROR] WARNING arraytypes.py(1269): FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
[INFO] DEBUG lazyflow.operators.classifierOperators: Features took 0.560179 seconds. Prediction took 10.067052 seconds. Subregion: start '[0, 0, 0]' stop '[1040, 1388, 2]'
[INFO] INFO ilastik.workflows.pixelClassification.pixelClassificationWorkflow: Completed Batch Processing
[INFO] ilastik execution finished successfully!
[INFO] Found dataset 'exported_data' of type 'uint8'
[INFO] Constructing output image of shape (1388, 1040, 1, 1, 1). Axis order: 'XYCZT'
[INFO] Deleted tmp file: /var/folders/tg/3hdw5s3s0hg4crdsqt5n2ywc0000gq/T/ilastik4j4907492669311425173_in_raw.h5
[INFO] Deleted tmp file: /var/folders/tg/3hdw5s3s0hg4crdsqt5n2ywc0000gq/T/ilastik4j9133301468090674222_out.h5

Analysis goals

Afterwards, the image will be skeletonized and analysed for statistics.

Challenges

Couldn’t address segmentation results window. I have tried listing all images, but it is still not recognised.

Hi @nghiaagent,

welcome to the image.sc community :slight_smile:

From the log it looks like segmentation did run successfully.

[INFO] ilastik execution finished successfully!
[INFO] Found dataset 'exported_data' of type 'uint8'
[INFO] Constructing output image of shape (1388, 1040, 1, 1, 1). Axis order: 'XYCZT'

There is the information that the data is loaded back into fiji. So if you execute the macro (without the saving to h5) a new window should pop up. Could you verify this?

Maybe a side question: Why do you export to .h5 from Fiji in order to import and resave as .tif?

Cheers