From 52e3436f61c62b18c8f7e0fbfb8329bde302e9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 15 Feb 2013 15:39:48 +0100 Subject: [PATCH] Fix integer type bugs in feature detection algorithms --- skimage/draw/_draw.pyx | 3 ++- skimage/feature/_daisy.py | 13 +++++++------ skimage/feature/_hog.py | 6 ++++-- skimage/feature/tests/test_hog.py | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index 4b7fb094..efd5fdc5 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -274,7 +274,8 @@ def circle_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t radius, return np.array(rr) + cy, np.array(cc) + cx -def ellipse_perimeter(int cy, int cx, int yradius, int xradius): +def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, + Py_ssize_t xradius): """Generate ellipse perimeter coordinates. Parameters diff --git a/skimage/feature/_daisy.py b/skimage/feature/_daisy.py index f83605b5..1bb8cbf5 100644 --- a/skimage/feature/_daisy.py +++ b/skimage/feature/_daisy.py @@ -180,7 +180,7 @@ def daisy(img, step=4, radius=15, rings=3, histograms=8, orientations=8, color = (1, 0, 0) desc_y = i * step + radius desc_x = j * step + radius - coords = draw.circle_perimeter(desc_y, desc_x, sigmas[0]) + coords = draw.circle_perimeter(desc_y, desc_x, int(sigmas[0])) draw.set_color(descs_img, coords, color) max_bin = np.max(descs[i, j, :]) for o_num, o in enumerate(orientation_angles): @@ -188,8 +188,8 @@ def daisy(img, step=4, radius=15, rings=3, histograms=8, orientations=8, bin_size = descs[i, j, o_num] / max_bin dy = sigmas[0] * bin_size * sin(o) dx = sigmas[0] * bin_size * cos(o) - coords = draw.line(desc_y, desc_x, desc_y + dy, - desc_x + dx) + coords = draw.line(desc_y, desc_x, int(desc_y + dy), + int(desc_x + dx)) draw.set_color(descs_img, coords, color) for r_num, r in enumerate(ring_radii): color_offset = float(1 + r_num) / rings @@ -199,7 +199,7 @@ def daisy(img, step=4, radius=15, rings=3, histograms=8, orientations=8, hist_y = desc_y + int(round(r * sin(t))) hist_x = desc_x + int(round(r * cos(t))) coords = draw.circle_perimeter(hist_y, hist_x, - sigmas[r_num + 1]) + int(sigmas[r_num + 1])) draw.set_color(descs_img, coords, color) for o_num, o in enumerate(orientation_angles): # Draw histogram bins @@ -209,8 +209,9 @@ def daisy(img, step=4, radius=15, rings=3, histograms=8, orientations=8, bin_size /= max_bin dy = sigmas[r_num + 1] * bin_size * sin(o) dx = sigmas[r_num + 1] * bin_size * cos(o) - coords = draw.line(hist_y, hist_x, hist_y + dy, - hist_x + dx) + coords = draw.line(hist_y, hist_x, + int(hist_y + dy), + int(hist_x + dx)) draw.set_color(descs_img, coords, color) return descs, descs_img else: diff --git a/skimage/feature/_hog.py b/skimage/feature/_hog.py index 8e8ea7f2..9fa018b7 100644 --- a/skimage/feature/_hog.py +++ b/skimage/feature/_hog.py @@ -142,8 +142,10 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8), centre = tuple([y * cy + cy // 2, x * cx + cx // 2]) dx = radius * cos(float(o) / orientations * np.pi) dy = radius * sin(float(o) / orientations * np.pi) - rr, cc = draw.bresenham(centre[0] - dx, centre[1] - dy, - centre[0] + dx, centre[1] + dy) + rr, cc = draw.bresenham(int(centre[0] - dx), + int(centre[1] - dy), + int(centre[0] + dx), + int(centre[1] + dy)) hog_image[rr, cc] += orientation_histogram[y, x, o] """ diff --git a/skimage/feature/tests/test_hog.py b/skimage/feature/tests/test_hog.py index 6f2d4cdf..cfef2da0 100644 --- a/skimage/feature/tests/test_hog.py +++ b/skimage/feature/tests/test_hog.py @@ -102,7 +102,7 @@ def test_hog_orientations_circle(): width = height = 100 image = np.zeros((height, width)) - rr, cc = draw.circle(height/2, width/2, width/3) + rr, cc = draw.circle(int(height / 2), int(width / 2), int(width / 3)) image[rr, cc] = 100 image = ndimage.gaussian_filter(image, 2)