diff --git a/skimage/measure/profile.py b/skimage/measure/profile.py index 823bd9da..5a754ee3 100644 --- a/skimage/measure/profile.py +++ b/skimage/measure/profile.py @@ -59,23 +59,17 @@ def profile_line(img, src, dst, linewidth=1, line_col = np.linspace(src_col, dst_col, length) line_row = np.linspace(src_row, dst_row, length) - # this if clause is necessary to keep the line centered on the true - # source and destination points. Otherwise, the computed line has - # an offset of `linewidth / 2` - if linewidth <= 1: - perp_lines = np.array([line_row[:, np.newaxis], - line_col[:, np.newaxis]]) - else: - # we subtract 1 from linewidth to change from pixel-counting - # (make this line 3 pixels wide) to point distances (the - # distance between pixel centers) - col_width = (linewidth - 1) * np.sin(-theta) / 2 - row_width = (linewidth - 1) * np.cos(theta) / 2 - perp_rows = np.array([np.linspace(row_i - row_width, row_i + row_width, - linewidth) for row_i in line_row]) - perp_cols = np.array([np.linspace(col_i - col_width, col_i + col_width, - linewidth) for col_i in line_col]) - perp_lines = np.array([perp_rows, perp_cols]) + # we subtract 1 from linewidth to change from pixel-counting + # (make this line 3 pixels wide) to point distances (the + # distance between pixel centers) + col_width = (linewidth - 1) * np.sin(-theta) / 2 + row_width = (linewidth - 1) * np.cos(theta) / 2 + perp_rows = np.array([np.linspace(row_i - row_width, row_i + row_width, + linewidth) for row_i in line_row]) + perp_cols = np.array([np.linspace(col_i - col_width, col_i + col_width, + linewidth) for col_i in line_col]) + perp_lines = np.array([perp_rows, perp_cols]) + if img.ndim == 3: pixels = [nd.map_coordinates(img[..., i], perp_lines, order=order, mode=mode, cval=cval)