Skip to content

Global cellpose normalisation to remove residual tiling grid - #44

Closed
mikemcka wants to merge 1 commit into
devfrom
feat/cellpose-global-normalization
Closed

mikemcka wants to merge 1 commit into
devfrom
feat/cellpose-global-normalization

Conversation

@mikemcka

@mikemcka mikemcka commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds an opt-in param cellpose_normalize_global (default false) to fix the residual tiling grid.

Why

Even with sopa's CLAHE/gaussian off, Cellpose still normalises each patch to its own 1–99 percentile, so the same cell gets a different scale in a dense vs. a sparse patch — a faint grid at patch seams. When enabled, the pipeline computes one [low, high] per channel from the whole image and reuses it for every patch, so the scale is identical everywhere.

Notes

  • Off by default; assumes cellpose_clip_limit = 0; supersedes cellpose_tile_norm_blocksize.
  • Adds cellpose_normalize_percentiles (default 1,99).
  • Still needs a GPU run on Seqera to confirm end-to-end — I couldn't test Cellpose on a GPU while developing this.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

nf-core pipelines lint overall result: Passed ✅ ⚠️

Posted for pipeline commit 1dee280

+| ✅  93 tests passed       |+
#| ❔  29 tests were ignored |#
!| ❗   5 tests had warnings |!
Details

❗ Test warnings:

  • pipeline_todos - TODO string in README.md: Add bibliography of tools and data used in your pipeline
  • pipeline_todos - TODO string in main.nf: Optionally add in-text citation tools to this list.
  • pipeline_todos - TODO string in main.nf: Optionally add bibliographic entries to this list.
  • pipeline_todos - TODO string in main.nf: Only uncomment below if logic in toolCitationText/toolBibliographyText has been filled!
  • pipeline_name_conventions - Naming does not adhere to nf-core conventions: Contains non alphanumeric characters

❔ Tests ignored:

  • files_exist - File is ignored: conf/igenomes.config
  • files_exist - File is ignored: conf/igenomes_ignored.config
  • files_exist - File is ignored: assets/multiqc_config.yml
  • files_exist - File is ignored: conf/igenomes.config
  • files_exist - File is ignored: conf/igenomes_ignored.config
  • files_exist - File is ignored: conf/test.config
  • files_exist - File is ignored: conf/test_full.config
  • files_exist - File is ignored: assets/multiqc_config.yml
  • files_exist - File is ignored: .github/ISSUE_TEMPLATE/config.yml
  • files_exist - File is ignored: .github/workflows/nf-test.yml
  • files_exist - File is ignored: .github/workflows/awstest.yml
  • files_exist - File is ignored: .github/workflows/awsfulltest.yml
  • files_exist - File is ignored: .github/workflows/download_pipeline.yml
  • files_exist - File is ignored: .github/workflows/fix-linting.yml
  • files_exist - File is ignored: .github/workflows/release-announcements.yml
  • files_exist - File is ignored: .github/workflows/template_version_comment.yml
  • files_exist - File is ignored: .github/actions/get-shards/action.yml
  • files_exist - File is ignored: .github/actions/nf-test/action.yml
  • files_exist - File is ignored: .github/actions/
  • files_exist - File is ignored: assets/nf-core-sp_segment_logo_light.png
  • files_exist - File is ignored: docs/images/nf-core-sp_segment_logo_light.png
  • files_exist - File is ignored: docs/images/nf-core-sp_segment_logo_dark.png
  • files_exist - File is ignored: tests/default.nf.test
  • nextflow_config - nextflow_config
  • files_unchanged - Required pipeline config not found - {'manifest.contributors'}
  • actions_nf_test - '.github/workflows/nf-test.yml' not found
  • actions_awstest - 'awstest.yml' workflow not found: /home/runner/work/sp_segment/sp_segment/.github/workflows/awstest.yml
  • schema_params - schema_params
  • multiqc_config - multiqc_config

✅ Tests passed:

Run details

  • nf-core/tools version 3.3.2
  • Run at 2026-08-20 01:57:13

Even with sopa's CLAHE and gaussian disabled, cellpose still rescales
every patch to that patch's own 1-99 percentile, so an identical cell
lands on a different scale in a dense versus a sparse patch -- the
residual tile grid at patch seams. Measured on one identical synthetic
cell across patches of differing content, its post-normalisation peak
varied by 284% under per-patch percentile and 1.8% under a shared
global scale.

Add opt-in `cellpose_normalize_global`: compute one [low, high] pair
per channel from the whole image (at `cellpose_normalize_percentiles`,
default 1,99) and pass it to cellpose as
`--method-kwargs '{"normalize": {"lowhigh": ...}}'`, so every patch
shares one scale. Bounds are ordered to match the channels cellpose
receives (membrane then nucleus for whole-cell).

The cellpose normalize dict is now single-sourced in the
SOPA_SEGMENTATIONCELLPOSE module rather than conf/modules.config,
because the global bounds are computed per sample at run time and sopa
would choke on --method-kwargs appearing twice. Precedence: global >
tile-local (cellpose_tile_norm_blocksize) > cellpose's stock
whole-patch percentile.

Off by default (preserves cellpose's stock contract); assumes
cellpose_clip_limit=0, since bounds are computed on raw intensities.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mikemcka
mikemcka force-pushed the feat/cellpose-global-normalization branch from 08e972c to 1dee280 Compare August 20, 2026 01:56
@mikemcka mikemcka closed this Aug 20, 2026
@mikemcka
mikemcka deleted the feat/cellpose-global-normalization branch August 20, 2026 04:07
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.

1 participant