use break instead of exception

This commit is contained in:
François Boulogne
2016-06-02 10:32:00 +02:00
committed by François Boulogne
parent 80e8544067
commit aea36e89d1
+8 -10
View File
@@ -458,16 +458,14 @@ def threshold_minimum(image, nbins=256, bias='min'):
max_iter = 10000
smooth_hist = np.copy(hist)
try:
for counter in range(max_iter):
smooth_hist = ndif.uniform_filter1d(smooth_hist, 3)
maximums = find_local_maxima(smooth_hist)
if len(maximums) < 3:
raise StopIteration
except StopIteration:
if len(maximums) != 2:
raise RuntimeError('Unable to find two maxima in histogram')
else:
for counter in range(max_iter):
smooth_hist = ndif.uniform_filter1d(smooth_hist, 3)
maximums = find_local_maxima(smooth_hist)
if len(maximums) < 3:
break
if len(maximums) != 2:
raise RuntimeError('Unable to find two maxima in histogram')
elif counter == max_iter - 1:
raise RuntimeError('Maximum iteration reached for histogram histogram'
'smoothing')