Skip to content

Add batch-wide histogram aggregation, Multi-Otsu thresholding, and QC sweep report#157

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-histogram-calculation-rules
Draft

Add batch-wide histogram aggregation, Multi-Otsu thresholding, and QC sweep report#157
Copilot wants to merge 2 commits intomainfrom
copilot/add-histogram-calculation-rules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Enables batchwide threshold optimization for SPIM segmentation: since acquisition parameters are constant within a batch, a single threshold should be computed from all subjects together rather than per-subject. Adds a pipeline from per-subject histogram → batch aggregation → Multi-Otsu → visual QC sweep across all subjects.

New rules (segmentation.smk)

  • compute_spim_histogram — computes intensity histogram from raw SPIM channel at an arbitrary pyramid level via Dask; saves counts + bin_edges as .npz
  • aggregate_histograms — sums per-subject .npz histograms into a single batch histogram (group datatype output)
  • multiotsu_from_batch_histogram — applies percentile-range filtering on the aggregated histogram, then runs Multi-Otsu; outputs thresholds.tsv + thresholds.png

New rule (qc.smk)

  • qc_batch_otsu_threshold_sweep — group-level HTML report: sweeps threshold values, showing one mid-volume 2D crop per subject as columns, so the user can immediately see whether a threshold generalises across the batch. Batch histogram PNG is embedded at the top.

New target rule (Snakefile)

  • all_batch_otsu_hist_qc — triggers all batchotsuthreshqc.html reports for every stains_for_seg × otsu_seg_methods combination

File layout

Rule Output
compute_spim_histogram sub-*/seg/stain-*/level-*/histogram.npz
aggregate_histograms group/stain-*/level-*/histogram.npz
multiotsu_from_batch_histogram group/stain-*/level-*/desc-otsu+k{k}i{i}_thresholds.{png,tsv}
qc_batch_otsu_threshold_sweep group/stain-*/desc-otsu+k{k}i{i}_batchotsuthreshqc.html

The per-subject qc_otsu_threshold_sweep and multiotsu rules are unchanged; the new batch pipeline is additive.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • zenodo.org
    • Triggering command: /usr/bin/python3 python3 ./spimquant/run.py /home/REDACTED/work/SPIMquant/SPIMquant/tests/bids_ds /tmp/test_out participant -np (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add rules for histogram calculation and threshold optimization Add batch-wide histogram aggregation, Multi-Otsu thresholding, and QC sweep report Apr 11, 2026
Copilot AI requested a review from akhanf April 11, 2026 00:05
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