Closed petsuter closed 1 year ago
Hi @petsuter Thanks for reporting this. I can reproduce.
Raising a ValueError
if len(hist) < 2
or return the uniform value appears to be a fix. Do you agree?
Hi @decorouz Thanks for reproducing. I agree returning the uniform value would be a useful fix, and also consistent with other thresholding methods in the same file. Example
Even better (but not strictly required to fix the bug) would be to reuse the same _validate_image_histogram
helper and also add an optional hist
input as in the other methods, which is more general and useful.
Hi @petsuter
Your suggestions are great. If you are feeling inspired and have time, you should create a PR for a fix. I think it would be appropriate to update test_triangle_uint_images
too?
Description:
Pass an uniform image to
skimage.filters.threshold_triangle
. This raises an exception with an unclear error message.It should probably return the uniform value as the threshold, or raise an exception with a clearer error message.
threshold_isodata
,threshold_li
,threshold_local
,threshold_mean
,threshold_niblack
,threshold_otsu
,threshold_sauvola
,threshold_yen
have no problem with an empty / uniform image.(
threshold_minimum
also fails:RuntimeError: Unable to find two maxima in histogram
)(
threshold_multiotsu
also fails:ValueError: After discretization into bins, the input image has only 1 different values. It cannot be thresholded in 3 classes. If there are more unique values before discretization, try increasing the number of bins (
nbins).
)Way to reproduce:
Version information: