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

[ENH] Update binarize_img for negative value handling #4121

Merged
merged 20 commits into from Nov 27, 2023

Conversation

smeisler
Copy link
Contributor

Addresses #3467.

This change introduces the two_sided argument for binarize_img which allows users to control whether the threshold is applied to the original value of the image (two_sided=False) or absolute value of the image (two_sided=True). The behavior does not change from what is was (two_sided was always True), but I think it should change to default to False as it is more intuitive when thresholding images with negative values.

I am also interested in expanding the function to include multiple operators (less than, more than, etc), but figured this is a good place to start that addresses the linked issue.

Add `two_sided` argument with argument deprecation warning
Copy link
Contributor

👋 @smeisler Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.

  • PR has an interpretable title.
  • PR links to Github issue with mention Closes #XXXX (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.

@smeisler smeisler changed the title [REF] Update binarize_img [REF] Update binarize_img for negative value handling Nov 25, 2023
Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d6d822d) 91.81% compared to head (4c13b5a) 91.81%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4121   +/-   ##
=======================================
  Coverage   91.81%   91.81%           
=======================================
  Files         144      144           
  Lines       16172    16173    +1     
  Branches     3360     3360           
=======================================
+ Hits        14849    14850    +1     
  Misses        781      781           
  Partials      542      542           
Flag Coverage Δ
macos-latest_3.10_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
macos-latest_3.11_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
macos-latest_3.12_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
macos-latest_3.8_test_plotting 91.60% <100.00%> (+<0.01%) ⬆️
macos-latest_3.9_test_plotting 91.61% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.10_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.11_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.12_test_plotting 91.64% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.12_test_pre 91.64% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.8_test_min 69.17% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.8_test_plot_min 91.36% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.8_test_plotting 91.60% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.9_test_plotting 91.61% <100.00%> (+<0.01%) ⬆️
windows-latest_3.10_test_plotting 91.62% <100.00%> (+<0.01%) ⬆️
windows-latest_3.11_test_plotting 91.62% <100.00%> (+<0.01%) ⬆️
windows-latest_3.12_test_plotting 91.62% <100.00%> (+<0.01%) ⬆️
windows-latest_3.8_test_plotting 91.58% <100.00%> (+<0.01%) ⬆️
windows-latest_3.9_test_plotting 91.58% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

Thx ! LGTM overall.

nilearn/image/image.py Outdated Show resolved Hide resolved
nilearn/image/tests/test_image.py Outdated Show resolved Hide resolved
smeisler and others added 2 commits November 25, 2023 08:46
Co-authored-by: bthirion <bertrand.thirion@inria.fr>
@smeisler smeisler changed the title [REF] Update binarize_img for negative value handling [ENH] Update binarize_img for negative value handling Nov 25, 2023
Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM, thx !

Copy link
Member

@ymzayek ymzayek left a comment

Choose a reason for hiding this comment

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

Thanks @smeisler ! Minor things

nilearn/image/image.py Outdated Show resolved Hide resolved
nilearn/image/image.py Outdated Show resolved Hide resolved
nilearn/image/image.py Outdated Show resolved Hide resolved
nilearn/image/tests/test_image.py Outdated Show resolved Hide resolved
Copy link
Member

@ymzayek ymzayek left a comment

Choose a reason for hiding this comment

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

Thanks for the quick changes. LGTM. Last thing then I think it should be good to go

nilearn/image/image.py Outdated Show resolved Hide resolved
Copy link
Member

@ymzayek ymzayek left a comment

Choose a reason for hiding this comment

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

Awesome thx! Once the CI finishes and is green, will merge

@ymzayek ymzayek merged commit c16146a into nilearn:main Nov 27, 2023
32 checks passed
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.

None yet

3 participants