How to Choose Filter and Threshold Parameters for Plant‑Mask GenerationLink
Goal: Find a set of parameters (a filter method, its specific controls, and a
min_threshold) that isolate the plant in a binary mask for your specific imaging setup.
The GUI offers several grayscale transformation methods to turn a colour image into a single feature image; the parameters of the selected method, together with the mask thresholds, are then used to produce the plant binary mask.




1. Launch the GUILink
conda activate plant3dvision
plant_masking # starts the app
If you already have a database to work on, you can also start the app with an explicit path and optionally open a specific scan:
plant_masking /path/to/FSDB --scan SCAN_ID
2. Load an ImageLink
- Use the Search box to filter the list of scans.
- Pick a Scan from the dropdown; the first image of the scan is loaded automatically.
- Use the Image slider (or the numeric index box) to browse the other images of the scan.
The original picture appears on the left panel of the display area.
3. Select a Filter MethodLink
The Method dropdown at the top of the controls panel chooses which grayscale transformation is applied. Only the controls relevant to the selected method are shown:
| Method | Controls shown | Typical use |
|---|---|---|
linear |
Color Space + 3 channel coefficients | Default; generic channel mixing |
excess_green |
Bright Threshold | Green vegetation on soil/brown bg |
green_fraction |
Bright Threshold | Green vegetation (normalized) |
luminance_thin_lines_enhancement |
Half Length | Thin bright structures (stems) |
When you switch method, the method‑specific controls are reset to their defaults.
4. Linear MethodLink
The linear filter computes a weighted sum of the three colour channels, optionally after converting the image to another colour space:
where p_1, p_2, p_3 are the three channels (e.g. R, G, B) and c_1, c_2, c_3 their weights.
4.1 Pick a Color Space (optional)Link
The dropdown Color Space lets you work in RGB (default), HSV, or YCbCr.
- Use RGB for most plant‑imaging cases.
- Switch to HSV or YCbCr only if the plant colors are not well separated in RGB (e.g., strong hue shifts).
4.2 Tune the Channel CoefficientsLink
Three horizontal sliders control the contribution of each color channel (values = 0 – 1).
| Slider | Default label | Typical plant‑specific advice |
|---|---|---|
| C₁ | Red / Hue / Luminance | Increase if the plant appears reddish or yellowish. |
| C₂ | Green / Saturation / Blue‑diff | Keep at 1.0 for healthy green foliage. |
| C₃ | Blue / Value / Red‑diff | Reduce to suppress background sky or water reflections. |
Tips
As you move a slider, the Filtered image (centre panel) updates instantly, letting you see how the grayscale intensity changes.
Remember
This is an additive RGB color model, see Wikipedia for detailed explanations.
5. Excess Green MethodLink
The excess green index measures how "green" a pixel is relative to its total brightness:
where r = R/(R+G+B), g = G/(R+G+B) and b = B/(R+G+B) are the normalized channels.
It is well suited to segment green plants from soil, mulch or other brownish backgrounds.
5.1 Bright ThresholdLink
The Bright Threshold slider (values = 0 – 1) zeroes out dark pixels before computing the index. Pixels whose total intensity R+G+B falls below this value are ignored, which guards against noisy dark pixels. Increase it if dark background noise appears in the mask.
6. Green Fraction MethodLink
The green fraction index is the green channel normalized by the total intensity:
Like excess green it highlights vegetation, but it is bounded in [0, 1] which can make the threshold choice more intuitive.
6.1 Bright ThresholdLink
As for excess green, the Bright Threshold slider (values = 0 – 1) sets to zero the pixels whose total intensity R+G+B falls below the chosen value. Use it to suppress noisy dark pixels.
7. Luminance Thin Lines Enhancement MethodLink
This method enhances thin bright lines (e.g. stems, petioles) in the luminance of the image. It keeps bright structures thinner than a reference size while removing flat or thicker regions, using the difference between morphological line openings and a box opening of matching size.
7.1 Half LengthLink
The Half Length slider (values = 1 – 10, integer) controls the half‑length of the line
structuring element: a value of 2 yields a 5‑pixel line. Increase it to detect thicker
structures, decrease it to isolate only the thinnest lines.
8. Set the Threshold RangeLink
Whatever the method, two spin boxes plus a slider control the final binary mask:
- Min Threshold: lower bound (default 0.30).
- Max Threshold: upper bound (default 1.00).
- Min Size: minimum connected‑component size in pixels (default 0, keeps every component).
Start by leaving Max Threshold at 1.00 and move Min Threshold downward until the plant silhouette is fully visible but background noise is minimized. Inversely, if the mask becomes too sparse, lower the value slightly.
If isolated specks of noise survive, increase Min Size to remove small connected components (0 – 25 pixels).
The Mask panel on the right shows the resulting binary image in real time.
9. Iterate Until SatisfiedLink
- Choose the method that best matches your scene, then adjust its specific controls and the
min_thresholdas described above. - Observe the three panels (Original | Filtered | Mask).
-
Confirm that:
- The whole plant (including stems) appears white in the mask.
- Unwanted bright artifacts (e.g., specular highlights) are either removed or acceptable for downstream analysis.
-
When the result looks good on the first image, repeat the same parameter set on a second image from the same dataset to verify robustness. Small illumination changes may require a modest tweak of the Min Threshold.
10. Record the Final ParametersLink
Click Export Parameters to save the current configuration (method, its controls, the
thresholds, min_size and dilation) to the scan's local_config.toml file.
Alternatively, write down the selected method, its specific parameters and the chosen
min_threshold (and max_threshold if you changed it).
Use these values in your reconstruction TOML configuration file.
Quick Reference (cheat‑sheet)Link
| Control | Applies to method | How to adjust | When to change |
|---|---|---|---|
| Method | All | Drop‑down menu | Pick the transformation that best separates the plant |
| Color Space | linear |
Drop‑down menu | Plant colour not well separated in RGB |
| Red / Hue / Y | linear |
Slider (0–1) | Plant has significant red/yellow component |
| Green / Sat / Cb | linear |
Slider (0–1) | Keep at 1.0 for typical green foliage |
| Blue / Val / Cr | linear |
Slider (0–1) | Reduce to suppress background blues |
| Bright Threshold | excess_green, green_fraction |
Slider (0–1) | Increase to cut dark background noise |
| Half Length | luminance_thin_lines_enhancement |
Slider (1–10) | Increase to detect thicker structures, decrease for thin lines |
| Min Threshold | All | Spin box (0.0–1.0, step 0.01) | Increase to cut background, decrease to fill gaps |
| Max Threshold | All | Spin box (0.0–1.0, step 0.01) | Rarely needed; keep at 1.0 unless you clip bright outliers |
| Min Size | All | Slider (0–25, step 1) | Increase to remove small isolated noise components |
By following these focused steps, you’ll quickly arrive at a reliable filter and threshold configuration that isolates your plant for downstream analysis. Happy masking!