Remove unnecessary if clause

The `if linewidth <= 1` was necessary because the coordinate systems
(pixel/point) were all muddled up. Now that it has been clarified,
`linewidth=1` works transparently!
This commit is contained in:
Juan Nunez-Iglesias
2014-01-29 22:52:49 +11:00
parent 4bc5d66060
commit d71cd4d750
+11 -17
View File
@@ -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)