Skip to content

[REF] Flip the bits on the histological profiles #274

Description

@ReinderVosDeWael

For the histological module "The Merker staining labels cell bodies, similar to Nissl staining, with a high contrast between black cell bodies on a light background (Merker, 1983). In the digitised images, darker colouring is represented by lower numbers (8bit graphics: 0–28 = black-white). It is common practice to invert the values of the intensity, such that image intensity increases with staining intensity." Paquola et al., 2021, eLife

Currently, these values are not inverted in BrainStat, we should add this as a default.

Note that this should not affect MPC computations.

Activity

  1. zihuaihuai commented on May 4, 2026

    @zihuaihuai
    Collaborator

    Still relevant. The current read_histology_profile returns the raw 8-bit values from BigBrainWarp, where lower = darker = more cell-dense — opposite to the convention used in Paquola et al. 2021 and most downstream BigBrain analyses.

    Two ways forward:

    1. Flip by default and add an invert=False escape hatch for users who depend on the current behaviour. This is the change the issue calls for and is the cleanest. The bit-flip itself is a one-liner: profiles = np.iinfo(profiles.dtype).max - profiles for the 8-bit array (or 255 - profiles if we keep it explicit). MPC (compute_mpc) is correlation-based, so partial correlations and gradients are unaffected, as the issue notes — but downstream code that inspects the raw profile values directly would see a flip, hence the toggle.
    2. Document only, no behaviour change. Safer for downstream reproducibility but leaves the "intuitive" convention out of reach by default.

    Option (1) seems preferable, paired with a clear note in the changelog and the read_histology_profile docstring. If anyone has objections — particularly if you have published pipelines that pin against current BrainStat output — please weigh in here before someone opens a PR.

  2. zihuaihuai commented on May 4, 2026

    @zihuaihuai
    Collaborator

    Implemented in #380. read_histology_profile now flips the BigBrainWarp 8-bit values so higher = darker = denser (matching Paquola et al. 2021), gated on invert: bool = True. Pass invert=False to keep the previous output. MPC and gradient computations are correlation-based, so they're unaffected by the flip — only direct intensity inspection changes.

  3. added a commit that references this issue on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PythonOn the Python implementationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions