Skip to content

Fix multi-channel handling #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

timtreis
Copy link
Member

I think the current implementation doesn't correctly handle images with 3+ channels, for example resulting in the following warning when rendering a 5 channel image:

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [0.01870049980776624..2.4537485582468284].
image

This PR proposes an alternative in which PCA is used to reduce an arbitrary amount of channels to 3 so that we can treat them as RGB:

image

@timtreis timtreis linked an issue Apr 22, 2025 that may be closed by this pull request
@timtreis
Copy link
Member Author

@Sonja-Stockhaus did we discuss this at one point? I've been ignoring that warning for a long time because it's thrown my matplotlib and doesn't fail

@timtreis
Copy link
Member Author

image
This PR also introduces a bg_threshold parameter based on which we can exclude pixels for the PCA normalisation, f.e. in this composite

@timtreis timtreis marked this pull request as draft April 23, 2025 12:30
@Sonja-Stockhaus
Copy link
Collaborator

@Sonja-Stockhaus did we discuss this at one point? I've been ignoring that warning for a long time because it's thrown my matplotlib and doesn't fail

Nope. I also don't remember ever trying to render sth with 3+ channels

@codecov-commenter
Copy link

codecov-commenter commented May 11, 2025

Codecov Report

Attention: Patch coverage is 86.59794% with 13 lines in your changes missing coverage. Please review.

Project coverage is 85.71%. Comparing base (7716d43) to head (2e991c5).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/render.py 88.05% 8 Missing ⚠️
src/spatialdata_plot/pl/utils.py 81.48% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #451      +/-   ##
==========================================
+ Coverage   84.92%   85.71%   +0.79%     
==========================================
  Files           8        8              
  Lines        1784     1869      +85     
==========================================
+ Hits         1515     1602      +87     
+ Misses        269      267       -2     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 89.26% <100.00%> (ø)
src/spatialdata_plot/pl/render_params.py 100.00% <100.00%> (ø)
src/spatialdata_plot/pl/utils.py 79.39% <81.48%> (+1.19%) ⬆️
src/spatialdata_plot/pl/render.py 95.52% <88.05%> (-0.86%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis changed the title Feature: PCA aggregation for n >= 4 channels in render_images Fix multi-channel handling May 11, 2025
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.

Feature: PCA aggregation for n >= 4 channels in render_images
3 participants