spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

Fix multi-channel handling

Open timtreis opened this issue 9 months ago • 4 comments

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 avatar Apr 22 '25 22:04 timtreis

@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 avatar Apr 22 '25 22:04 timtreis

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 avatar Apr 22 '25 22:04 timtreis

@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

Sonja-Stockhaus avatar Apr 23 '25 13:04 Sonja-Stockhaus

Codecov Report

:x: Patch coverage is 86.59794% with 13 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 85.71%. Comparing base (7716d43) to head (2e991c5). :warning: Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/render.py 88.05% 8 Missing :warning:
src/spatialdata_plot/pl/utils.py 81.48% 5 Missing :warning:
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%) :arrow_up:
src/spatialdata_plot/pl/render.py 95.52% <88.05%> (-0.86%) :arrow_down:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar May 11 '25 19:05 codecov-commenter