Repository navigation
H&E tissue mask: rule he_tissue_v2 estimates the white (0 % kept on grey-glass cores) - #622
Draft
guijacquemet wants to merge 2 commits into
Draft
guijacquemet wants to merge 2 commits into
guijacquemet wants to merge 2 commits into
Conversation
…he plane he_tissue_v1 fixes the white at 255. On the Zenodo 4550300 TMA cores the glass is near (127, 135, 145), so every pixel read as stained (H >= 0.05 everywhere, no background) and tissue-mask kept 0.0 % of every core. he_tissue_v2 estimates each channel's white as the median of the brightest 0.1 % of pixels (by R+G+B), rescales with normalization's rescale_to_white and applies v1's components unchanged. It is the new default of RunInputs.he_tissue_mask, preview_he_tissue_mask, he_tissue_mask_array, tissue-mask and the notebook card; v1 is unchanged and still offered. Cores 1B_D9 and 2B_A6: 0.0 % -> 46.8 % and 44.4 % kept; white-glass slides are unchanged within 0.4 points; blank slides keep nothing. Regression fixture: a 320 x 320 crop of core 1B_D9 (CC-BY-4.0) with its generator script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G3qp9AEzaRH4WH1TyJRA61
v2's rescaling moves to he_tissue_rule.white_rescaled, and the lineage's run facts (the RGB header override item, the recorded pixel size) move to the new module he_tissue_run_facts (orchestration layer). No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G3qp9AEzaRH4WH1TyJRA61
This was referenced Dec 3, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
morphobricks-preprocessing tissue-mask(rulehe_tissue_v1) kept 0.0 % of every H&E core of Zenodo 4550300 ("nothing kept: an empty region"). fiberfeatures then measuredroi_area_px = 0and NaN features. This PR adds rulehe_tissue_v2and makes it the default.Diagnosis (reproduced on the real data)
Data: the record's
validation2.zip(SHA-256f7eb874b…), cores1B_D9_WB.tif(8c74cadd…) and2B_A6_WB.tif(6e49f686…): 2048 × 2048uint8,YXS, photometric MINISBLACK, so the run usesrgb_header_override = true.OD >= 0.22, so the background test (max(OD) < 0.08) never fires.H >= 0.05also holds everywhere. The fractions werenuclei 1.0, kept 0.0: the whole plane was read as nuclei.The fix:
he_tissue_v2(provisional)v2 is v1 run on the plane after rescaling it to its own white:
R+G+Bis at or above the 99.9th percentile ofR+G+B(NumPy, methodlinear), raised to at least 1 (he_tissue_rule.estimate_white).rescale_to_white(N69:clip(rint(I*255/white), 0, 255)as uint8). No colour maths is added here.componentsare identical to v1's.Version semantics follow the design ("changing any number gives
he_tissue_v2and never changes v1"):input.whiteset to"estimated"and awhiteentry stating steps 1 and 2.rule="he_tissue_v1").By module:
he_tissue_rule.py: the v2 record,HE_TISSUE_V2,DEFAULT_RULE,estimate_white,estimates_white.he_tissue_mask.py:rule_on_planeestimates the white and rescales beforeE,HandOD. The new fieldTissueMaskPreview.whiteholds the white used (Noneunder v1). The lineage line's keys are unchanged; the white follows from the source content digest and the rule record.he_tissue_run_facts.py(new, orchestration layer): the lineage's run facts (override_record,pixel_size_record), moved out ofhe_tissue_mask.pyunchanged so that file stays under the 600-line code rule.run_inputs_tissue.py,he_tissue_array.py,cli_tissue_mask.py,notebook_tissue_mask.py: default rule is v2, and the texts are updated.he-tissue-mask.md(a new "he_tissue_v2" section with the diagnosis, the numbers and the limitation), contract §15.3/§15.4, user guide, README, AGENTS.md, and CHANGELOG under Unreleased (v0.10.1).Before / after: kept share
1B_D9_WB.tif2B_A6_WB.tif1B_F3_WB.tif2B_G5_WB.tif2B_H2_WB.tif2B_G3_WB.tif2B_E9_WB.tif(a thin strip of tissue on glass)I also inspected the v2 masks as overlays: glass, fat holes and lumens are excluded, nuclei are excluded and dilated, and stroma is kept.
White-glass slides (CMU-1.svs, Aperio, CC0, SHA-256 checked against the design):
Decisions (for the owner)
RunInputs.he_tissue_mask,preview_he_tissue_maskandhe_tissue_mask_array(tests/test_brick_api_surface.pyis updated). If you prefer to keep v1 as the default and make v2 opt-in, that is a one-line change ofDEFAULT_RULEplus the three re-exported constants.R+G+B. It is chosen because it saturates at 255 on normal slides (so v2 equals v1 there) and finds the glass on these scans. I fixed the 99.9 percentile after trying 99 % and 99.9 %. 99 % moved CMU-1 dense tiles by up to 4 points; 99.9 % moved them by at most 0.4.Notes for review
rule="he_tissue_v1"is the choice for such planes on a white-balanced scanner.test_he_tissue_consumer_gate.pyskips without fiberfeatures v0.7.0), and the notebook card in a real JupyterLab or Colab.he_eosinmaps on these scans are still computed against white 255. The region mask is now right, but the eosin values measured inside it sit on a shifted baseline. That is a fiberfeatures or normalization question (normalization'she_eosinpreset takes nowhite).tests/data/he_core_1B_D9_crop.npz, a 320 × 320 crop of 1B_D9 at full resolution (160 KiB). The record's licence is CC-BY-4.0, and the attribution and the checked digests are in the generator,tests/data/make_he_core_crop.py.What the owner's local gate should check
On the same clean install, with v0.10.1 or this branch:
keptwell above 0 %, about 47 % for1B_D9_WB.tifand 44 % for2B_A6_WB.tif, and never "nothing kept: an empty region" for a core with tissue.rule.versionis 2.MaskRequest("HETissueV2", "region")should reportroi_area_px > 0and finite features.Tests
tests/test_he_tissue_v2.py, 18 tests:rgb_header_override = true.rule="he_tissue_v1", and the pinned defaults and texts say v2.python tools/check.py(ruff check, ruff format --check, pytest, code rules) at1345159: 9288 passed, 24 skipped; code rules pass. Run locally: GitHub Actions is blocked.Generated by Claude Code