From 1170d87ba442acee7187f32b019725cbc261f0fa Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Mon, 27 Jan 2014 15:18:06 +1100 Subject: [PATCH] Update _calc_vert for simplicity --- skimage/measure/profile.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/skimage/measure/profile.py b/skimage/measure/profile.py index b19e1f74..3912fc4e 100644 --- a/skimage/measure/profile.py +++ b/skimage/measure/profile.py @@ -1,15 +1,10 @@ import numpy as np import scipy.ndimage as ndi -def _calc_vert(img, x1, x2, y1, y2, linewidth): - # Quick calculation if perfectly horizontal - pixels = img[min(y1, y2): max(y1, y2) + 1, - x1 - linewidth / 2: x1 + linewidth / 2 + 1] - - # Reverse index if necessary - if y2 > y1: - pixels = pixels[::-1, :] - +def _calc_vert(img, col, src_row, dst_row, linewidth): + # Quick calculation if perfectly vertical + pixels = img[src_row:dst_row:np.sign(dst_row - src_row), + col - linewidth / 2: col + linewidth / 2 + 1] return pixels.mean(axis=1)[:, np.newaxis] @@ -66,7 +61,7 @@ def profile_line(img, src, dst, linewidth=1, mode='constant', cval=0.0): img = img[:, :, np.newaxis] img = np.rollaxis(img, -1) - intensities = np.hstack([_calc_vert(im, src_col, dst_col, + intensities = np.hstack([_calc_vert(im, src_col, src_row, dst_row, linewidth) for im in img]) return intensities