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

feat: Add option to combine channels using sum and max #1159

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Jul 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced channel combining functionality with the CombineChannels class, allowing users to combine image channels using modes like Max or Sum.
  • Bug Fixes

    • Updated the method signature in ImageProjection to improve image handling.
  • Tests

    • Added tests for the new channel combining functionality to ensure robustness.

@Czaki Czaki added this to the 0.15.4 milestone Jul 18, 2024
Copy link
Contributor

sourcery-ai bot commented Jul 18, 2024

🧙 Sourcery has finished reviewing your pull request!


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

coderabbitai bot commented Jul 18, 2024

Walkthrough

The changes introduce a new CombineChannels class for image transformation by combining different channels in various modes such as Max and Sum. The combine_channels.py file adds this class, and the relevant imports and exports are updated in the __init__.py. Additionally, the get_fields_per_dimension method in image_projection.py now operates directly on an Image object. Tests for these new functionalities are added in test_image_adjustment.py.

Changes

File Path Change Summary
package/.../image_transforming/__init__.py Added CombineChannels import, updated image_transform_dict, and modified __all__.
package/.../image_transforming/combine_channels.py Introduced CombineChannels class for combining image channels with methods for various operations.
package/.../image_transforming/image_projection.py Updated get_fields_per_dimension to work with Image object and cleaned up imports.
package/tests/test_PartSegCore/test_image_adjustment.py Added tests for CombineChannels and new function get_cube_image_2ch().

Poem

In code so bright, where channels blend,
New methods rise, a helping friend.
With Sum or Max, they merge with grace,
Transforming images, face to face.
In tests they dance, in harmony,
Combining light, for all to see.
🌟🐇📸


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98af5f4 and 8466a88.

Files selected for processing (8)
  • package/PartSeg/_roi_analysis/partseg_settings.py (1 hunks)
  • package/PartSeg/common_gui/image_adjustment.py (1 hunks)
  • package/PartSegCore/image_transforming/init.py (1 hunks)
  • package/PartSegCore/image_transforming/combine_channels.py (1 hunks)
  • package/PartSegCore/image_transforming/image_projection.py (2 hunks)
  • package/PartSegCore/image_transforming/interpolate_image.py (1 hunks)
  • package/PartSegCore/image_transforming/swap_time_stack.py (1 hunks)
  • package/PartSegCore/image_transforming/transform_base.py (1 hunks)
Additional comments not posted (13)
package/PartSegCore/image_transforming/__init__.py (3)

2-2: LGTM! Import statement for CombineChannels.

The import statement for CombineChannels is correctly added.


8-8: LGTM! Update to image_transform_dict.

The CombineChannels class is correctly added to the image_transform_dict.


10-10: LGTM! Update to __all__.

The __all__ list is correctly updated to include CombineChannels.

package/PartSegCore/image_transforming/transform_base.py (1)

21-21: LGTM! Update to method signature for get_fields_per_dimension.

The method signature change to accept an Image object is consistent with the new functionality.

However, ensure that all calls to get_fields_per_dimension are updated to match the new signature.

Verification successful

LGTM! Update to method signature for get_fields_per_dimension.

The method signature change to accept an Image object is consistent with the new functionality. All calls to get_fields_per_dimension have been updated to match the new signature.

  • Definitions:

    • package/PartSegCore/image_transforming/combine_channels.py
    • package/PartSegCore/image_transforming/swap_time_stack.py
    • package/PartSegCore/image_transforming/image_projection.py
    • package/PartSegCore/image_transforming/interpolate_image.py
    • package/PartSegCore/image_transforming/transform_base.py
  • Usage:

    • package/PartSeg/common_gui/image_adjustment.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 'get_fields_per_dimension'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 'get_fields_per_dimension'

Length of output: 3601

package/PartSegCore/image_transforming/swap_time_stack.py (1)

21-21: LGTM! Update to method signature for get_fields_per_dimension.

The method signature change to accept an Image object is consistent with the new functionality.

However, ensure that all calls to get_fields_per_dimension are updated to match the new signature.

Verification successful

All calls to get_fields_per_dimension have been updated to match the new signature.

The method signature change to accept an Image object is consistently applied across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 'get_fields_per_dimension'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the method usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 'get_fields_per_dimension'

Length of output: 3601

package/PartSeg/common_gui/image_adjustment.py (1)

25-25: LGTM! Update to FormWidget instantiation.

The change simplifies the code by passing the image object directly.

However, ensure that the FormWidget class can handle the image object correctly.

package/PartSegCore/image_transforming/interpolate_image.py (1)

17-18: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to get_fields_per_dimension match the new signature.

Verification successful

Verify the function calls to get_fields_per_dimension match the new signature.

The function get_fields_per_dimension is used in multiple files. Ensure that all calls to this function pass an Image object as an argument.

  • package/PartSeg/common_gui/image_adjustment.py

    • Line: form_widget = FormWidget(val.get_fields_per_dimension(image), initial_values)
  • package/PartSegCore/image_transforming/swap_time_stack.py

    • Line: def get_fields_per_dimension(cls, image: Image):
  • package/PartSegCore/image_transforming/interpolate_image.py

    • Line: def get_fields_per_dimension(cls, image: Image) -> List[Union[str, AlgorithmProperty]]:
  • package/PartSegCore/image_transforming/image_projection.py

    • Line: def get_fields_per_dimension(cls, image: Image):
  • package/PartSegCore/image_transforming/transform_base.py

    • Line: def get_fields_per_dimension(cls, image: Image) -> List[Union[str, AlgorithmProperty]]:
  • package/PartSegCore/image_transforming/combine_channels.py

    • Line: def get_fields_per_dimension(cls, image: Image) -> List[Union[str, AlgorithmProperty]]:

All instances appear to follow the new signature, passing an Image object as an argument.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 $'get_fields_per_dimension'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all function calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 $'get_fields_per_dimension'

Length of output: 3601

package/PartSegCore/image_transforming/combine_channels.py (4)

19-20: LGTM!

The method correctly returns a list of algorithm properties with a default combine mode.


23-27: LGTM!

The method correctly returns a list of algorithm properties for each channel in the image.


34-53: LGTM!

The method correctly combines channels in the image based on the specified combine mode and updates the image accordingly.


56-60: LGTM!

The method correctly calculates initial values for the algorithm properties based on the image spacing.

package/PartSegCore/image_transforming/image_projection.py (1)

70-70: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to get_fields_per_dimension match the new signature.

Verification successful

Let's correct the rg command to use the appropriate file type for Python files and re-run the script to verify the function usage in the codebase.


Verified: All function calls to get_fields_per_dimension match the new signature.

The code changes are consistent across the codebase, and the function usage has been updated appropriately.

  • package/PartSeg/common_gui/image_adjustment.py
  • package/PartSegCore/image_transforming/transform_base.py
  • package/PartSegCore/image_transforming/swap_time_stack.py
  • package/PartSegCore/image_transforming/interpolate_image.py
  • package/PartSegCore/image_transforming/image_projection.py
  • package/PartSegCore/image_transforming/combine_channels.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 $'get_fields_per_dimension'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify all function calls to `get_fields_per_dimension` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 $'get_fields_per_dimension'

Length of output: 3601

package/PartSeg/_roi_analysis/partseg_settings.py (1)

109-113: LGTM!

The method now correctly includes a check for the equality of image.channels to ensure consistency.

@Czaki Czaki changed the title fead: Add option to combine channels using sum and max feat: Add option to combine channels using sum and max Jul 18, 2024
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.06%. Comparing base (aac66a7) to head (2efeb0f).
Report is 50 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1159      +/-   ##
===========================================
+ Coverage    93.05%   93.06%   +0.01%     
===========================================
  Files          208      209       +1     
  Lines        32763    32830      +67     
===========================================
+ Hits         30486    30553      +67     
  Misses        2277     2277              

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

Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8466a88 and 2efeb0f.

Files selected for processing (3)
  • package/PartSegCore/image_transforming/init.py (1 hunks)
  • package/PartSegCore/image_transforming/combine_channels.py (1 hunks)
  • package/tests/test_PartSegCore/test_image_adjustment.py (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • package/PartSegCore/image_transforming/init.py
  • package/PartSegCore/image_transforming/combine_channels.py
Additional comments not posted (6)
package/tests/test_PartSegCore/test_image_adjustment.py (6)

5-5: Imports look good.

The imported classes CombineChannels, CombineMode, and InterpolateImage are necessary for the new tests.


23-27: Function get_cube_image_2ch looks good.

The function correctly creates a 2-channel cube image and returns an Image object.


118-125: Test method test_simple looks good.

The test correctly sets up the image, applies the CombineChannels transformation with the Max mode, and verifies the results.


126-130: Test method test_no_channels looks good.

The test correctly sets up the image, applies the CombineChannels transformation with no specific channel settings, and verifies the results.


131-138: Test method test_sum looks good.

The test correctly sets up the image, applies the CombineChannels transformation with the Sum mode, and verifies the results.


139-145: Test method test_max looks good.

The test correctly sets up the image, applies the CombineChannels transformation with the Max mode, and verifies the results.

@Czaki Czaki merged commit 46be04f into develop Jul 19, 2024
55 checks passed
@Czaki Czaki deleted the feat/merge_channels branch July 19, 2024 08:13
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.

1 participant