[英]Binary mask from two segmentation curves
兩個分割曲線以1-d numpy數組形式存儲在r2(圖像中的底線)和r1(圖像中的上線)中。 我正在嘗試創建一個二進制掩碼。 除兩條曲線內的區域外,其他所有地方均為黑色:白色。 到目前為止,我已經嘗試了以下代碼,該代碼適用於直線,但不適用於基於另一個stackoverflow答案的曲線:
def line_func(col, s, e):
return (s + (e - s) * col / im.shape[1]).astype(np.int)
r1, r2 = [20, 25], [30, 35]
rows, cols = np.indices(im.shape)
m1 = np.logical_and(rows > line_func(cols, *r1),
rows < line_func(cols, *r2))
im+= 255 * (m1)
plt.imshow(im, cmap='gray')
從兩條曲線的點創建一個多邊形,然后使用該多邊形填充白色區域。 如果我們將曲線視為一組X值,然后視為兩組不同的Y值,則應執行以下操作:
from matplotlib.patches import Polygon
X = ...
Y1, Y2 = ...
points = list(zip(X, Y1)) + list(reversed(zip(X, Y2)))
polygon = Polygon(points)
# Now fill the polygon with one color, and everything else with a different color
在此處查看有關matplotlib中的排水多邊形的更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.