8000 fix: Drop imagej LUTs of size `24*x` by Czaki · Pull Request #1227 · 4DNucleome/PartSeg · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Drop imagej LUTs of size 24*x #1227

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

Merged
merged 2 commits into from
Dec 7, 2024
Merged

fix: Drop imagej LUTs of size 24*x #1227

merged 2 commits into from
Dec 7, 2024

Conversation

Czaki
Copy link
Collaborator
@Czaki Czaki commented Dec 7, 2024

In the past, The PartSeg wrote LUTs using 64 bits instead of 8 bits. I do not know how to decode it, so better drop it.

Summary by Sourcery

Fix the handling of LUTs in PartSeg by dropping those with 64-bit integers and refactor the adjust_color function to return a tuple instead of a list.

Bug Fixes:

  • Fix the issue of incorrectly written LUTs in PartSeg by dropping LUTs with 64-bit integers.

Enhancements:

  • Refactor the adjust_color function to return a tuple instead of a list for color adjustments.

Summary by CodeRabbit

  • New Features

    • Introduced a new static method for improved handling of ImageJ color metadata, enhancing robustness when reading ImageJ files.
  • Bug Fixes

    • Adjusted the color adjustment function to return a tuple for better compatibility with integer lists, improving color processing accuracy.
  • Tests

    • Updated test assertions to reflect changes in how default coloring is retrieved, ensuring accurate validation of image properties.

Copy link
Contributor
sourcery-ai bot commented Dec 7, 2024

Reviewer's Guide by Sourcery

This PR fixes a bug in handling ImageJ LUTs (Look-Up Tables) where they were previously written using 64 bits instead of 8 bits. The implementation adds validation for LUT data and adjusts color handling in the napari plugin loader.

Class diagram for Image Reader LUT Handling

classDiagram
    class ImageReader {
        +read_resolution_from_tags(image_file)
        +read_imagej_metadata(image_file)
        +_read_imagej_colors(image_file)
    }

    ImageReader : +_read_imagej_colors(image_file)
    ImageReader : +read_imagej_metadata(image_file)
    ImageReader : -colors
    ImageReader : +colors = _read_imagej_colors(image_file)

    note for ImageReader "_read_imagej_colors is a new static method to handle LUTs validation."
Loading

File-Level Changes

Change Details Files
Added validation for ImageJ LUT data to handle incorrectly saved color information
  • Added new static method _read_imagej_colors to validate LUT data
  • Added check for LUT data shape to identify incorrectly saved 64-bit values
  • Modified read_imagej_metadata to use the new validation method
package/PartSegImage/image_reader.py
Updated color adjustment function in napari plugin loader
  • Changed return type annotation from list[float] to tuple[float]
  • Modified list comprehension to use generator expression for color value normalization
package/PartSegCore/napari_plugins/loader.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor
coderabbitai bot commented Dec 7, 2024

Walkthrough

The pull request introduces changes to the adjust_color function in loader.py, altering its return type from a list to a tuple when the input is a list of integers. The function's internal logic is updated to use a generator expression for constructing the output. Additionally, a new static method _read_imagej_colors is added to the TiffImageReader class in image_reader.py to improve color handling from ImageJ metadata. The overall structure and logic of existing functions remain unchanged.

Changes

File Path Change Summary
package/PartSegCore/napari_plugins/loader.py Updated adjust_color function return type from list[float] to tuple[float] and modified internal logic.
package/PartSegImage/image_reader.py Added static method _read_imagej_colors to process ImageJ color metadata, enhancing robustness.
package/tests/test_PartSegImage/test_image_writer.py Updated test assertions in test_imagej_write_all_metadata to reflect changes in how default coloring is retrieved.

Possibly related PRs

Suggested labels

skip check PR title

Poem

In fields of color, bright and bold,
Adjustments made, a tale retold.
From lists to tuples, changes flow,
ImageJ's hues now brightly glow.
With every tweak, our code does sing,
A rabbit's joy in every spring! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf18e82 and 7bdde52.

📒 Files selected for processing (2)
  • package/PartSegImage/image_reader.py (1 hunks)
  • package/tests/test_PartSegImage/test_image_writer.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package/PartSegImage/image_reader.py
🔇 Additional comments (1)
package/tests/test_PartSegImage/test_image_writer.py (1)

97-97: LGTM! The assertion update aligns with the PR objectives.

The change from image.default_coloring to image.get_imagej_colors() correctly reflects the fix for ImageJ LUT handling.

Let's verify that this is the only test affected by the LUT changes:

✅ Verification successful

The change is correct, but there are related test cases that need attention

The verification revealed two important findings:

  • In test_image.py, there are tests using default_coloring that are marked as deprecated since PartSeg 0.15.4
  • In test_image_writer.py, there's another test case test_imagej_write_with_metadata that uses default_coloring assertions but in a different context (verifying color channel values)

The current change in test_imagej_write_all_metadata is correct as it specifically tests ImageJ color preservation. The other test cases serve different purposes:

  • The deprecated tests in test_image.py are intentionally testing the legacy behavior
  • The assertions in test_imagej_write_with_metadata verify specific color channel values, not the ImageJ color mapping
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other tests that might need similar updates
# Look for tests using default_coloring or ImageJ-related color handling

# Search for tests using default_coloring
rg -l "default_coloring" "package/tests"

# Search for ImageJ-related color tests
rg -l "imagej.*color" "package/tests"

Length of output: 228


Script:

#!/bin/bash
# Let's examine the content of test_image.py to see if it needs similar updates
rg "default_coloring" "package/tests/test_PartSegImage/test_image.py" -B 2 -A 2

# Also check for any other ImageJ color-related assertions in test_image_writer.py
rg "assert.*color" "package/tests/test_PartSegImage/test_image_writer.py" -B 2 -A 2

Length of output: 2656


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Czaki - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -30,7 +30,7 @@ def adjust_color(color: typing.Union[str, list[int]]) -> typing.Union[str, list[
# case when color is in format #RGBA
return color[:4]
elif isinstance(color, list):
return [color[i] / 255 for i in range(3)]
return (color[i] / 255 for i in range(3))
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Convert generator expression to tuple explicitly

The generator expression should be converted to a tuple explicitly using tuple(). Currently, it returns a generator that can only be iterated once, which could cause issues if the caller needs to use the values multiple times.

Copy link
sonarqubecloud bot commented Dec 7, 2024

@Czaki Czaki changed the title fix: drop wrong imagej LUTs fix: Drop imagej LUTs of size 24*x Dec 7, 2024
@Czaki Czaki added the skip check PR title skip spellcheking PR title label Dec 7, 2024
@Czaki Czaki added this to the 0.16.0 milestone Dec 7, 2024
Copy link
codecov bot commented Dec 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.12%. Comparing base (323b509) to head (7bdde52).
Report is 20 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1227      +/-   ##
===========================================
- Coverage    93.14%   93.12%   -0.03%     
===========================================
  Files          210      210              
  Lines        33172    33178       +6     
===========================================
- Hits         30899    30897       -2     
- Misses        2273     2281       +8     

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Czaki Czaki merged commit 755a481 into develop Dec 7, 2024
59 of 61 checks passed
@Czaki Czaki deleted the drop_bad_lut branch December 7, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip check PR title skip spellcheking PR title
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0