Thanks to visit codestin.com
Credit goes to github.com

Skip to content

make the low contrast check optional when saving images #3653

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
Feb 10, 2019
Merged

make the low contrast check optional when saving images #3653

merged 2 commits into from
Feb 10, 2019

Conversation

christian-rauch
Copy link
Contributor

Description

This PR makes the low constrast check optional when saving images.
As described in #2531 the low contrast check delays the image export and is generally only useful for natural images.

References

Fixe #2531

For reviewers

(Don't remove the checklist below.)

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

Copy link
Member

@hmaarrfk hmaarrfk left a comment

Choose a reason for hiding this comment

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

It looks good. To get this PR as fast as possible, I suggest you don't try to change the default behaviour.

It may be desirable to change it, but as far as you are concerned for your batch scripts, it would be better for you to forgo that request in this particular PR.

If the PR gets approved quickly enough, it might even make it in 0.14.2 ;)

@hmaarrfk
Copy link
Member

@christian-rauch I'm having the discussion here because github often closes the mini discussions that are around comments:

Unfortunately, scikit-image has a deprecation cycle policy.
http://scikit-image.org/docs/stable/contribute.html#deprecation-cycle

Sometimes, often for warnings, it is broken, but often requires discussion.

In this particular case, mostly because the release of 0.14.2 should be imminent (due to the fact that numpy 1.16 broke scikit-image), I suggest you keep the default behaviour change as a separate PR. It is therefore in your best interest to minimize the discussion as much as possible.

@jni
Copy link
Member

jni commented Jan 17, 2019

Thanks for the comments and PR, @christian-rauch! And thanks for chiming in, @hmaarrfk! Good advice. =) I think either way this won't be in 0.14.2 though, @stefanv and I are working on getting this out the door today. (Though no promises because crap always goes wrong. LOL)

Anyway, regarding low contrast, the problem is that before that message, we would always get people saying "I used scikit-image to save an image and it's all black when I open it in [Preview/Photoshop/Whatever]". All the time. That's what the warning is supposed to prevent, and actually my totally unscientific impression is that it's worked.

So my intuition is that we should:

  • definitely indeed add an option to skip the check
  • don't skip by default
  • add a documentation page that explains the issue (especially with regards to data types), and make the warning both explain how to turn it off and link to the page with more info about the whole thing.

I am amenable to be convinced that I should just delete the damn thing altogether, but that'll take a bit more work. =)

I do also think long term we want to offload all io to imageio, but that is also a hard sell.

@christian-rauch
Copy link
Contributor Author

To increase the probability of being merged (and to make exporting less annoying) I reverted to the default behaviour. To prevent the check and warnings, check_contrast has to be set to False by the user.
I will leave the discussion on whether or not to remove the low contrast check completely for a later PR :-)

Copy link
Member

@hmaarrfk hmaarrfk left a comment

Choose a reason for hiding this comment

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

needs a small test.

@@ -203,6 +203,10 @@ def test_imsave_incorrect_dimension():
with testing.raises(ValueError):
with expected_warnings([fname + ' is a low contrast image']):
imsave(fname, np.zeros((2, 3, 2)))
# test that low contrast check is ignored
with testing.raises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

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

why does this raise valueerror?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. I just amended the part that is related to the low contrast warning exception.

Copy link
Member

Choose a reason for hiding this comment

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

It just doesn't like the fact that there are 2 channels in the last dimension of the array.
Not an ideal test, but I'm ok with how this looks now.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I looked into it a little further, there isn't currently a place to put these "tests for all plugins". So this is as good of a place as any. I don't think PIL is going away any time soon.

@hmaarrfk
Copy link
Member

@jni, this is looking good. Minimally invasive 9 line PR, maybe good enough to get backported too ;)

@hmaarrfk
Copy link
Member

@scikit-image/core I think this PR is good to go if anybody has time to give it a second pass.

@ahojnnes
Copy link
Member

Looks great to me, thanks for the contribution!

@ahojnnes ahojnnes merged commit 4769172 into scikit-image:master Feb 10, 2019
@christian-rauch christian-rauch deleted the optional_low_contrast_check branch February 10, 2019 20:46
@jni
Copy link
Member

jni commented Feb 11, 2019

🎉

@stefanv
Copy link
Member

stefanv commented Feb 13, 2019

Should this PR be accompanied by plans for deprecation?

@jni
Copy link
Member

jni commented Feb 17, 2019

@stefanv imho it's a valuable check to have around. See my comment above regarding its original motivation. However I won't stand in the way if others prefer making "off" the default.

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.

5 participants