Skip to content

Replace fixed histogram range/bins in multiotsu with percentile-based range and bin-width; add threshold sweep QC report#146

Merged
akhanf merged 2 commits intomainfrom
copilot/update-multiotsu-options
Apr 5, 2026
Merged

Replace fixed histogram range/bins in multiotsu with percentile-based range and bin-width; add threshold sweep QC report#146
akhanf merged 2 commits intomainfrom
copilot/update-multiotsu-options

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

The multiotsu histogram used a hardcoded intensity range [0, 1000] with 1000 bins, which breaks on datasets with different dynamic ranges. This replaces those fixed parameters with a percentile-based range and bin-width approach, and adds an optional target rule to visually optimize the threshold.

Parameter changes

  • --seg_hist_range--seg_hist_percentile_range (default: [1, 99], type: float) — range adapts to each dataset
  • --seg_hist_bins--seg_hist_bin_width (default: 1, type: float) — bin count derived as ceil((range_hi - range_lo) / bin_width)

multiotsu.py updates

Loads a downsampled pyramid level (tries levels 5→1) to compute percentiles efficiently, then uses the resulting range and bin width to build the histogram before running multi-Otsu thresholding.

New: all_otsu_hist_qc target rule

Invoke to produce one self-contained HTML report per subject/stain/method:

snakemake all_otsu_hist_qc

Each report contains:

  • The multi-Otsu histogram PNG (from the multiotsu rule)
  • A grid of 2D axial crops with the binary mask overlaid in red, across 10 evenly-spaced threshold values spanning the 1st–99th percentile range

This allows visual inspection to pick the best threshold before committing to a full segmentation run. The rule reuses the bias-field corrected zarr already produced for the multiotsu rule (temp file kept alive until both consumers finish).

…shold sweep QC report

Agent-Logs-Url: https://github.com/khanlab/SPIMquant/sessions/6e50e573-7300-48e8-9c59-9808da92d8f5

Co-authored-by: akhanf <11492701+akhanf@users.noreply.github.com>
@akhanf akhanf merged commit 8e54ac5 into main Apr 5, 2026
2 checks passed
@akhanf akhanf deleted the copilot/update-multiotsu-options branch April 5, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants