Skip to content

Add per-subject bias-corrected intensity histogram QC#156

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-per-subject-histogram-functionality
Draft

Add per-subject bias-corrected intensity histogram QC#156
Copilot wants to merge 2 commits intomainfrom
copilot/add-per-subject-histogram-functionality

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Adds a QC rule that generates a per-subject, per-stain intensity histogram from bias-field-corrected intensities sampled patch-wise from within the brain mask — avoiding the cost of processing the full zarr volume.

Changes

  • segmentation.smk / n4_biasfield.py: Add biasfield ome.zarr output to the n4_biasfield rule (mirrors existing gaussian_biasfield behaviour) by passing upsampled_ome_zarr_path to apply_scaled_processing.

  • qc.smk — new rule qc_bias_corrected_histogram: Takes the raw SPIM zarr, the downsampled bias field ome.zarr (keyed on correction_method, works for both n4 and gaussian), and the brain mask NIfTI. Parameterised via existing n_patches_per_label, patch_size, and patch_seed config keys.

  • qc_bias_corrected_histogram.py — new script:

    1. Wraps the brain mask NIfTI as a single-label ZarrNiiAtlas (no TSV needed) and calls sample_region_patches to draw random patch centres in physical space.
    2. Extracts full-res patches from the raw zarr at level 0; extracts the corresponding region from the bias field at registration_level within its pyramid (covering the same physical extent with patch_size / 2**registration_level voxels).
    3. Upsamples the bias field crop to the raw patch shape via scipy.ndimage.zoom(order=1) (linear; avoids ringing on a smooth field).
    4. Divides raw by bias field per-patch, accumulates intensities, and renders the same 4-panel histogram PNG as qc_intensity_histogram.
  • Snakefile: Adds bias-corrected histograms to all_qc for stains_for_seg, gated on do_seg.

Copilot AI and others added 2 commits April 10, 2026 15:36
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