-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added support for binary images in is_low_contrast to fix imshow of binary images #5247
Conversation
Hello @MadsDyrmann! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-02-23 16:44:59 UTC |
Thanks @MadsDyrmann! Very happy to merge this fix. Do you want to add a test to make sure it doesn't break in the future? Having said all this, in the medium term (~1y) we aim to pull out the matplotlib dependency and make sure the focus of scikit-image is on image processing, not display or IO. So you should probably start migrating your downstream code to start using plt.imshow directly. |
May I recommend plotly.express.imshow as an alternative? With |
@mkcor well, plotly plots it in a web browser, which some people are allergic to—cough cough cough. 😜 |
@jni just an alternative... 😜 |
@@ -647,6 +647,10 @@ def is_low_contrast(image, fraction_threshold=0.05, lower_percentile=1, | |||
if image.shape[2] == 3: | |||
image = rgb2gray(image) | |||
|
|||
if image.dtype == bool: | |||
return image.any() and (image == False).any() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but if a boolean image has both True and False values, then the function should return False, shouldn't it? I have the impression that the returned value should be
return not(image.any() and (image == False).any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway a test (as @jni suggested) could either prove me that I'm wrong :-) or check that the behaviour is as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When image.dtype == bool
, is_low_contrast
is True
when the image is constant: all filled with True
or with False
, ie when False
and True
are not both in image
.
So I think that you are right @emmanuelle!
BTW, I think that this test must take place at the beginning of the function, even before checking for image dimensions, because rgb2gray
will convert the image to floating point...
@MadsDyrmann are the different suggestions clear for you? Thanks again for the PR! |
Hi @MadsDyrmann, To add a test, edit file Hope that helps! |
Hi everyone, |
@MadsDyrmann, I have resumed this PR in #5467 so am closing this one as outdated. Please confirm your name and email address either here or in that PR if you want to be attributed as a co-author on the commits. |
Description
imshow stopped working when plotting boolean images, since np.percentile no longer support boolean arrays. This PR makes sure that is_low_contrast does not fail when the input is a boolean array.
This is a small test-script that would fail before this change:
Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.