From d9196be3c3ba3158e1960541cd059c9861e294fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Thu, 1 Aug 2013 08:45:11 +0200 Subject: [PATCH] Fix loop ranges of rank filter kernel functions --- skimage/filter/rank/generic_cy.pyx | 4 ++-- skimage/filter/rank/percentile_cy.pyx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/skimage/filter/rank/generic_cy.pyx b/skimage/filter/rank/generic_cy.pyx index 44c51d55..9815d6ea 100644 --- a/skimage/filter/rank/generic_cy.pyx +++ b/skimage/filter/rank/generic_cy.pyx @@ -29,7 +29,7 @@ cdef inline double _kernel_autolevel(Py_ssize_t* histo, double pop, dtype_t g, if delta > 0: return (max_bin - 1) * (g - imin) / delta else: - return imax - imin + return 0 else: return 0 @@ -321,7 +321,7 @@ cdef inline double _kernel_otsu(Py_ssize_t* histo, double pop, dtype_t g, mu1 = 0. max_sigma_b = 0. - for i in range(1, max_bin): + for i in range(max_bin): P = histo[i] / pop new_q1 = q1 + P if new_q1 > 0: diff --git a/skimage/filter/rank/percentile_cy.pyx b/skimage/filter/rank/percentile_cy.pyx index 5989cdca..e951a76e 100644 --- a/skimage/filter/rank/percentile_cy.pyx +++ b/skimage/filter/rank/percentile_cy.pyx @@ -17,7 +17,7 @@ cdef inline double _kernel_autolevel(Py_ssize_t* histo, double pop, dtype_t g, if pop: sum = 0 p1 = 1.0 - p1 - for i in range(max_bin - 1): + for i in range(max_bin): sum += histo[i] if sum > p0 * pop: imin = i @@ -55,7 +55,7 @@ cdef inline double _kernel_gradient(Py_ssize_t* histo, double pop, dtype_t g, imin = i break sum = 0 - for i in range((max_bin - 1), -1, -1): + for i in range(max_bin - 1, -1, -1): sum += histo[i] if sum >= p1 * pop: imax = i @@ -135,7 +135,7 @@ cdef inline double _kernel_enhance_contrast(Py_ssize_t* histo, double pop, imin = i break sum = 0 - for i in range((max_bin - 1), -1, -1): + for i in range(max_bin - 1, -1, -1): sum += histo[i] if sum > p1 * pop: imax = i