Skip to content

Show warnings for input image type in threshold_otsu - #1876

Merged
jni merged 3 commits into
scikit-image:masterfrom
OrkoHunter:threshold_otsu_grayscale
Jan 17, 2016
Merged

jni merged 3 commits into
scikit-image:masterfrom
OrkoHunter:threshold_otsu_grayscale

Conversation

@OrkoHunter

Copy link
Copy Markdown
Contributor

Address #1867

The threshold_otsu function only supports grayscale image as input and results in unexpected behavior when used with an RGB image.
This PR tries to improve the documentation of the function and raise a temporary warning for the usage with an RGB image.

Question : Should we convert the image into grayscale as @JDWarner suggested by using rgb2gray and return the result for it? Or should we let the user use the faulty output? If we go with rgb2gray solution, we can probably add a line about it in the warning.

@OrkoHunter
OrkoHunter force-pushed the threshold_otsu_grayscale branch from 54541ed to 10135d8 Compare January 14, 2016 12:50
@jni

jni commented Jan 15, 2016

Copy link
Copy Markdown
Member

Hey @OrkoHunter!

Small comment: "Grayscale" -> "grayscale".

Slightly bigger comment: the message is not quite descriptive enough. I would say something like:

"threshold_otsu is only expected to work correctly for grayscale images; image shape %s looks like an RGB image" % image.shape

You need to be specific because if someone gives a 3D grayscale image that happens to have (3) as the last dimension, the user will be confused.

Bigger comment: you should now wrap any test that raises a warning using with expected_warnings(['grayscale']): from skimage/_shared/_warnings.py. (Use git grep to find usage examples for that pattern.)

Finally, I don't think we should convert to grayscale before the computation because iirc that uses the luminance channel after a conversion to Lab colorspace. It would then be meaningless to use that threshold on the original RGB.

Thanks!

@JDWarner

Copy link
Copy Markdown
Contributor

The idea would be convert to luminance, then return the threshold of the
luminance image.

I cannot think of any reason we need to provide per-channel thresholding
for the vast majority of users. And, anyone who wants that can pass
channel(s) individually.
On Jan 14, 2016 10:00 PM, "Juan Nunez-Iglesias" [email protected]
wrote:

Hey @OrkoHunter https://github.com/OrkoHunter!

Small comment: "Grayscale" -> "grayscale".

Slightly bigger comment: the message is not quite descriptive enough. I
would say something like:

"threshold_otsu is only expected to work correctly for grayscale images; image shape %s looks like an RGB image" % image.shape

You need to be specific because if someone gives a 3D grayscale image that
happens to have (3) as the last dimension, the user will be confused.

Bigger comment: you should now wrap any test that raises a warning using with
expected_warnings(['grayscale']): from skimage/_shared/_warnings.py. (Use git
grep to find usage examples for that pattern.)

Finally, I don't think we should convert to grayscale before the
computation because iirc that uses the luminance channel after a conversion
to Lab colorspace. It would then be meaningless to use that threshold on
the original RGB.

Thanks!

—
Reply to this email directly or view it on GitHub
#1876 (comment)
.

@OrkoHunter
OrkoHunter force-pushed the threshold_otsu_grayscale branch 2 times, most recently from 1cb04cc to ff03535 Compare January 15, 2016 04:47
@OrkoHunter

Copy link
Copy Markdown
Contributor Author

@jni All three comments addressed. Any other test using threshold_otsu are not raising any warning except these two. Hence I warped them only.

@OrkoHunter
OrkoHunter force-pushed the threshold_otsu_grayscale branch from ff03535 to a2d75de Compare January 15, 2016 05:03
@OrkoHunter

Copy link
Copy Markdown
Contributor Author

Had to replace {} with {0} just for python 2.6 support. Related : how far along we are, with #1854 ?

@JDWarner

Copy link
Copy Markdown
Contributor

We've got to keep 2.6 until 0.12 is tagged and released - soon, but not yet

  • after which we can drop it.
    On Jan 15, 2016 12:07 AM, "Himanshu Mishra" [email protected]
    wrote:

Had to replace {} with {0} just for python 2.6 support. Related : how far
along we are, with #1854
#1854 ?

—
Reply to this email directly or view it on GitHub
#1876 (comment)
.

jni added a commit that referenced this pull request Jan 17, 2016
Show warnings for input image type in threshold_otsu
@jni
jni merged commit b7fa0ac into scikit-image:master Jan 17, 2016
@jni

jni commented Jan 17, 2016

Copy link
Copy Markdown
Member

@OrkoHunter great, thanks!

@JDWarner yes, per-channel can be done manually, which is what I do now. But automatically converting to luminance is, imho, dangerous, because the user will not have the luminance image, and they might try to apply the threshold directly to the RGB image (as per our many examples). It's magical behaviour that quite plausibly would cause errors.

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.

3 participants