From 391e9761571ebd486e2ff7784b0a64a964580ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 31 Jul 2013 19:24:18 +0200 Subject: [PATCH] Add specific branch for the percentile p0 = 0 case --- skimage/filter/rank/percentile_cy.pyx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/skimage/filter/rank/percentile_cy.pyx b/skimage/filter/rank/percentile_cy.pyx index ffa5e1b0..8fad59c5 100644 --- a/skimage/filter/rank/percentile_cy.pyx +++ b/skimage/filter/rank/percentile_cy.pyx @@ -161,11 +161,15 @@ cdef inline double _kernel_percentile(Py_ssize_t* histo, double pop, dtype_t g, cdef Py_ssize_t sum = 0 if pop: - for i in range(max_bin): - sum += histo[i] - if sum >= p0 * pop: - break - + if p0 == 0: # make sure p0 == 0 returns the minimum filter + for i in range(max_bin): + if histo[i]: + break + else: + for i in range(max_bin): + sum += histo[i] + if sum >= p0 * pop: + break return i else: return 0