简体   繁体   English

来自两条分割曲线的二值蒙版

[英]Binary mask from two segmentation curves

Two segmentation curves are stored in r2(bottom line in image) and r1(upper line in image) as 1-d numpy arrays. 两个分割曲线以1-d numpy数组形式存储在r2(图像中的底线)和r1(图像中的上线)中。 I'm trying to create an binary mask; 我正在尝试创建一个二进制掩码。 black everywhere except the region inside those two curves: white. 除两条曲线内的区域外,其他所有地方均为黑色:白色。 So far, I have tried the following code which works for lines but not for curves based on another stackoverflow answer: 到目前为止,我已经尝试了以下代码,该代码适用于直线,但不适用于基于另一个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')

seg2和seg1

Create a polygon from the points of both curves, and then use that to fill a white area. 从两条曲线的点创建一个多边形,然后使用该多边形填充白色区域。 If we treat the curves as one set of X values, and then two different sets of Y values, we should do the following: 如果我们将曲线视为一组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

See more about draing polygons in matplotlib here 此处查看有关matplotlib中的排水多边形的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Python中的两条分割线创建二进制掩码 - Create binary mask from two segmentation lines in Python 在从实例分割掩码中提取的二值对象掩码图像中提取感兴趣对象的二值边界图像 - Extracting a binary boundary image for object of interest in a binary object mask image extracted from an instance segmentation mask Python中的平滑二进制分割掩码图像 - Smooth binary segmentation mask image in Python keras flow_from_dataframe 用于图像分割(即使用二进制掩码作为标签) - keras flow_from_dataframe for image segmentation (i.e. with a binary mask as label) 如何堆叠多个二进制掩码以创建用于多类分割的单个掩码? - How to stack multiple binary masks to create a single mask for multiclass segmentation? 从二进制掩码裁剪图像 - Cropping image from a binary mask 从阈值蒙版生成圆形粒子的分割蒙版? - Generating a segmentation mask for circular particles from threshold mask? 如何从 output 分类器创建分割掩码? - How to create segmentation mask from output classifier? 从掩码 rcnn 中提取分割掩码 - extract segmentation masks from mask rcnn 从Python中的二进制蒙版检索轮廓蒙版的快速方法 - Fast method to retrieve contour mask from a binary mask in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM