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

NF: Adding correct_mask to median_otsu #3140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pjsjongsung
Copy link
Contributor

@pjsjongsung pjsjongsung commented Mar 20, 2024

This PR aims to add a function that removes holes or islands of a binary mask to median_otsu.

The function was already being used in
dipy/nn/utils.py, so it has been moved to dipy/segment/utils.py, as it makes more sense for mask correction to be in segmentation module.

Slice-wise hole removal was excluded from the function, since it can cause huge false positives if there is a lack of axial slices.

Finally, the function's name has been changed to
remove_holes_and_islands, to be more explicit about the functionality.

This PR is related to #3124

@pep8speaks
Copy link

pep8speaks commented Mar 20, 2024

Hello @pjsjongsung, Thank you for updating !

Line 313:81: E501 line too long (81 > 80 characters)

Comment last updated at 2024-04-16 17:46:25 UTC

@arokem
Copy link
Contributor

arokem commented Mar 20, 2024

Could you please add a test of remove_holes_and_islands?

@pjsjongsung pjsjongsung force-pushed the seg_corr_change branch 2 times, most recently from 19b14ce to e62f7c3 Compare March 21, 2024 00:58
Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @pjsjongsung,

Thank you for this. See below for minor comments

@@ -297,7 +298,7 @@ def __predict(self, x_test):
def predict(self, T1, affine,
voxsize=(1, 1, 1), batch_size=None,
return_affine=False, return_prob=False,
largest_area=True):
Copy link
Member

Choose a reason for hiding this comment

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

You might have to use deprecate_params since this method is available the 2 last release at least.

Copy link
Member

Choose a reason for hiding this comment

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

to discuss

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Do you know an example of deprecation by change in parameter name in DIPY I could follow?

Copy link
Member

Choose a reason for hiding this comment

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

here it is :

@deprecated_params('sh_order', 'sh_order_max', since='1.9', until='2.0')

correct_mask : bool, optional
Whether to remove potential holes or islands.
Useful for solving minor errors.
Default is True
Copy link
Member

Choose a reason for hiding this comment

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

default to remove

Copy link
Member

Choose a reason for hiding this comment

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

Can you address this?

@skoudoro
Copy link
Member

Can you also rebase or merge master? Thank you

@pjsjongsung pjsjongsung force-pushed the seg_corr_change branch 3 times, most recently from b485557 to a306942 Compare March 26, 2024 00:28
Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 83.87097% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 83.62%. Comparing base (f2f72f0) to head (2e3c310).

❗ Current head 2e3c310 differs from pull request most recent head df24170. Consider uploading reports for the commit df24170 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3140      +/-   ##
==========================================
- Coverage   83.65%   83.62%   -0.04%     
==========================================
  Files         153      153              
  Lines       21272    21281       +9     
  Branches     3434     3425       -9     
==========================================
  Hits        17796    17796              
- Misses       2618     2625       +7     
- Partials      858      860       +2     
Files Coverage Δ
dipy/nn/utils.py 100.00% <ø> (ø)
dipy/nn/evac.py 89.14% <83.33%> (+0.38%) ⬆️
dipy/segment/mask.py 79.48% <66.66%> (-0.52%) ⬇️
dipy/segment/utils.py 86.36% <86.36%> (ø)

... and 103 files with indirect coverage changes

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @pjsjongsung,

Sorry for the late review. See below some comments. It is almost ready to go

correct_mask : bool, optional
Whether to remove potential holes or islands.
Useful for solving minor errors.
Default is True
Copy link
Member

Choose a reason for hiding this comment

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

Can you address this?

except ValueError:
warnings.warn('The mask has no background. \
Returning the original mask',
DeprecationWarning, stacklevel=2)
Copy link
Member

Choose a reason for hiding this comment

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

This is not a DeprecationWarning. I will keep it a UserWarning

dipy/segment/tests/test_utils.py Show resolved Hide resolved
@@ -124,7 +125,7 @@ def crop(vol, mins, maxs):


def median_otsu(input_volume, vol_idx=None, median_radius=4, numpass=4,
autocrop=False, dilate=None):
autocrop=False, dilate=None, correct_mask=True):
Copy link
Member

Choose a reason for hiding this comment

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

I will call this finalize_mask or something similar

correct_mask sounds like there is a bug so why should we put it False? lol

dipy/nn/evac.py Outdated
def predict(self, T1, affine,
voxsize=(1, 1, 1), batch_size=None,
return_affine=False, return_prob=False,
largest_area=True):
correct_mask=True):
Copy link
Member

Choose a reason for hiding this comment

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

same comment as below

@pjsjongsung
Copy link
Contributor Author

Sorry about the late response. Hopefully it is all resolved!

@skoudoro
Copy link
Member

skoudoro commented Apr 9, 2024

Hi @pjsjongsung,

I did not look yet but your test is failing:

=========================== short test summary info ============================
FAILED segment/tests/test_utils.py::test_remove_holes_and_islands - AssertionError: 
Arrays are not equal

Mismatched elements: 34970 / 64000 (54.6%)
Max absolute difference: 1.0
Max relative difference: 1.0
 x: array([[[1, 1, 1, ..., 0, 1, 1],
        [1, 1, 1, ..., 0, 1, 1],
        [1, 1, 1, ..., 1, 0, 1],...
 y: array([[[ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],...
===== 1 failed, 1020 passed, 65 skipped, 8 warnings in 1785.02s (0:29:45) ======

Can you look closely at this PR? thanks !

This PR aims to add a function that removes holes or islands of a binary
mask to median_otsu.

The function was already being used in
dipy/nn/utils.py, so it has been moved to dipy/segment/utils.py, as it
makes more sense for mask correction to be in segmentation module.

Slice-wise hole removal was excluded from the function, since it can
cause huge false positives if there is a lack of axial slices.

Finally, the function's name has been changed to
remove_holes_and_islands, to be more explicit about the functionality.

Related parameter name and its descriptions have been changed as well.
@pjsjongsung
Copy link
Contributor Author

My bad. I didn't think the test would fail since it worked before when it was in a different module. Changed the test so that it would not create non realistic tasks where the method would fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants