Skip to content

Commit

Permalink
doc: Update pixel classification
Browse files Browse the repository at this point in the history
* updated screenshots for 2.0.0
* simplified example macro (with more complex macro in `examples/`).
* fix: pc output is _not_ a label image!
  • Loading branch information
k-dominik committed Sep 25, 2023
1 parent a912f82 commit c979fc9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
51 changes: 18 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Found at `Plugins -> ilastik -> Configure ilastik executable location`.

### Pixel Classification and Autocontext

Pixel Classification and Autocontext workflow have similar input settings.
[Pixel Classification](https://www.ilastik.org/documentation/pixelclassification/pixelclassification) and [Autocontext](https://www.ilastik.org/documentation/autocontext/autocontext) workflow have similar input settings.

The Pixel Classification Workflow can be found at `Plugins -> ilastik -> Run Pixel Classification Prediction`, the Autocontext Workflow at `Plugins -> ilastik -> Run Autocontext Prediction`.

Expand All @@ -135,43 +135,28 @@ The Pixel Classification Workflow can be found at `Plugins -> ilastik -> Run Pix

* if _Probabilities_ was selected: a multi-channel float image that you can _e.g._ threshold to obtain a
segmentation ![Pixel Classification Output: Probabilities](./doc/screenshots/IJ-PC-predictions.png)
* or a _Segmentation_:a single-channel image where each pixel gets a value corresponding to an _object ID_ inside a _connected component_.
It is recommended to apply a LUT (e.g. `Image -> Lookup Tables -> glasbey`) to the result in order to see the _segmentation_ output.
* or a _Segmentation_:a single-channel image where each pixel gets a value corresponding to the label class.
e.g. all pixels belonging to your first label, will have the value `1`, all that belong to the 2nd class, will have the value `2` and so on.
ilastik will assign classes based on the _highest_ probability label for each pixel.
It is recommended to apply a LUT (e.g. `Image -> Lookup Tables -> glasbey`) to the result in order to see the _segmentation_ output.
![Pixel Classification Output: Segmentation](./doc/screenshots/IJ-PC-segmentation.png).

#### Batch processing
The macro below demonstrates how to apply pixel classification to all HDF5 files in a given input directory and save
resulting probability maps in separate HDF5 files inside the input directory.
```
// set global variables
pixelClassificationProject = "<ILASTIK_PROJECT_PATH>";
outputType = "Probabilities"; // or "Segmentation"
inputDataset = "data";
outputDataset = "exported_data";
axisOrder = "tzyxc";
compressionLevel = 0;
// process all H5 files in a given directory
dataDir = "<DATASET_DIR>";
fileList = getFileList(dataDir);
for (i = 0; i < fileList.length; i++) {
// import image from the H5
fileName = dataDir + fileList[i];
importArgs = "select=" + fileName + " datasetname=" + inputDataset + " axisorder=" + axisOrder;
run("Import HDF5", importArgs);
#### Example macro usage

// run pixel classification
inputImage = fileName + "/" + inputDataset;
pixelClassificationArgs = "projectfilename=" + pixelClassificationProject + " saveonly=false inputimage=" + inputImage + " pixelclassificationtype=" + outputType;
run("Run Pixel Classification Prediction", pixelClassificationArgs);
A simple example macro that opens a `.tif` file and processes it with a pre-trained ilastik pixel classification project would look like the following:

// export probability maps to H5
outputFile = dataDir + "output" + i + ".h5";
exportArgs = "select=" + outputFile + " datasetname=" + outputDataset + " compressionlevel=" + compressionLevel;
run("Export HDF5", exportArgs);
}
```javascript
project = "/absolute/path/to/some/directory/pixel_class_2d_cells_apoptotic.ilp";
input = "/absolute/path/to/some/directory/2d_cells_apoptotic.tif";

type = "Probabilities";

open(input);
run("Run Pixel Classification Prediction", "projectfilename=[" + project + "] input=[" + input + "] pixelclassificationtype=[" + type + "]");
```
replace `<DATASET_DIR>` with the input dataset where the HDF5 files reside (don't forget the trailing slash `/`) and `<ILASTIK_PROJECT_PATH>` with the path to your ilastik Pixel Classification project file.

A more complex example can be found in [`./examples/pixel_classification.ijm`](./examples/pixel_classification.ijm).


### Object Classification
Found at `Plugins -> ilastik -> Run Object Classification Prediction`.
Expand Down
Binary file modified doc/screenshots/IJ-PC-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/screenshots/IJ-PC-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/screenshots/IJ-PC-predictions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/screenshots/IJ-PC-segmentation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 32 additions & 6 deletions examples/pixel_classification.ijm
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
#@ File (label = "Project file", style = "file") project
// Lines that start with "//" are comments.

// Lines that start with "#@" declare input parameters that interactively ask the user for values.
// You can remove those lines and set input parameters explicitly in order to run the macro without further user interaction.

#@ File (label = "Project file", style = "file") pixelClassificationProject
// project = "/absolute/path/to/some/directory/pixel_class_2d_cells_apoptotic.ilp";

#@ File (label = "Input file", style = "file") input
// input = "/absolute/path/to/some/directory/2d_cells_apoptotic.tif";
#@ File (label = "Input file", style = "directory") dataDir
// dataDir = "/absolute/path/to/some/directory/";

// set global variables
outputType = "Probabilities"; // or "Segmentation"
inputDataset = "data";
outputDataset = "exported_data";
axisOrder = "tzyxc";
compressionLevel = 0;

// process all H5 files in a given directory
fileList = getFileList(dataDir);
for (i = 0; i < fileList.length; i++) {
// import image from the H5
fileName = dataDir + fileList[i];
importArgs = "select=" + fileName + " datasetname=" + inputDataset + " axisorder=" + axisOrder;
run("Import HDF5", importArgs);

type = "Probabilities";
// run pixel classification
inputImage = fileName + "/" + inputDataset;
pixelClassificationArgs = "projectfilename=" + pixelClassificationProject + " saveonly=false inputimage=" + inputImage + " pixelclassificationtype=" + outputType;
run("Run Pixel Classification Prediction", pixelClassificationArgs);

open(input);
run("Run Pixel Classification Prediction", "projectfilename=[" + project + "] input=[" + input + "] pixelclassificationtype=[" + type + "]");
// export probability maps to H5
outputFile = dataDir + "output" + i + ".h5";
exportArgs = "select=" + outputFile + " datasetname=" + outputDataset + " compressionlevel=" + compressionLevel;
run("Export HDF5", exportArgs);
}

0 comments on commit c979fc9

Please sign in to comment.