mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
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:
+11
-17
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user