Skip to content
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

fix: fix adjusting contrast limits for rgb data #276

Merged
merged 5 commits into from
Jul 22, 2024

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Jul 19, 2024

While working on reproducing of performance problem for points and shapes, I found that adjusting contrast limits do not work for data with 3 channels, that are represented as RGB data.

This PR contains the following changes:

  1. change channel_changed from local function to class method
  2. generalize _channel_changed to accept any dimensional data.
  3. fix AnnData initialization for rgb data

has_adata = layer is not None and layer.metadata.get("adata") is not None

# has_adata is added so we see the channels in the view widget under vars
if layer is None or not is_image or not has_sdata or not has_adata:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should look like

Suggested change
if layer is None or not is_image or not has_sdata or not has_adata:
if layer is None or not is_image or not has_sdata or not has_adata or image.rgb:

Comment on lines +306 to +313
current_point = list(event.value)
displayed = self._viewer.dims.displayed

for i, (lo_size, hi_size, cord) in enumerate(zip(layer.data[-1].shape, layer.data[0].shape, displayed)):
if i in displayed:
current_point[i] = slice(None)
else:
current_point[i] = int(cord * lo_size / hi_size)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is logic for any dimensional data.

If you are 100% sure that data will always be 2D, then this logic may be obsolete.
If contrast limits needs to be calculated for the whole channel, not only the visible portion, then it is also overcomplicated. But then, for 3D data, should be no recalculation when change Z slice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we will not be sure about this. SpatialData already does have 3D models. Where bugs occur for 3D napari-spatialdata should be adjusted.

@melonora
Copy link
Collaborator

I will first add #153 . That PR required some upstream changes that I have now implemented. I will then check how your PR interacts with it.

Copy link
Collaborator

@melonora melonora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor changes to take into account the changes made in #153. Thanks @Czaki !

Copy link
Collaborator

@melonora melonora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preapprove awaiting latest tests

@melonora melonora merged commit 5a57eeb into scverse:main Jul 22, 2024
6 checks passed
@Czaki Czaki deleted the fix_calculate_brightness branch July 22, 2024 17:14
LucaMarconato added a commit that referenced this pull request Aug 19, 2024
* fix #282 (error in channel selection due to #153)

* cleanup commented code

* fix test slider python 3.11
Copy link

codecov bot commented Oct 20, 2024

Codecov Report

Attention: Patch coverage is 27.27273% with 24 lines in your changes missing coverage. Please review.

Project coverage is 63.08%. Comparing base (3976825) to head (bdc527d).
Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
src/napari_spatialdata/_view.py 25.00% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #276      +/-   ##
==========================================
- Coverage   63.69%   63.08%   -0.62%     
==========================================
  Files          19       19              
  Lines        2628     2636       +8     
==========================================
- Hits         1674     1663      -11     
- Misses        954      973      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

2 participants