如何擦除由线段和颜色块界定的区域?
给出下图:
A 和 B 的位置已知,图片的其余部分只是原始的像素数据(仅红色和白色像素)。我可以用什么算法来擦除AB右边的部分?
Given the picture below:
The position of A and B is known, the rest of the picture is just raw pixel data (only red and white pixels). What algorithm can I use to erase the part to the right of AB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个点定义一条线。线方程将必须删除的像素分开。如果要以新边框平滑地跟随形状曲线的方式删除点,则需要某种方法来插入形状边框(基于边框中其他点的信息)。该插值必须通过两个黑点。现在,如果您有插值,您可以计算两个黑点之间的插值曲线,并将曲线上的所有点设置为白色。我可以建议至少再使用曲线上的一个点,并使用一些三次样条插值。
编辑:
根据您的评论。
那么算法很简单:保留一个从较低点(A)开始并沿着边界(A')移动的指针,直到到达另一个点。这可以通过检查当前指针位置的邻居并比较颜色来完成。现在,当您移动指针时,删除从指针 (A') 到点 AB(绿色)之间定义的线(蓝色)的红点线。当该行与另一个黑点相同时(例如A'和B在同一行),就有一个指针位置。然后以与跟踪边界相同的方式从 B 点开始一个新指针,并删除两个指针 A' 和 B' 之间的红色像素。
Having two points define a line. The equation of line separates pixels that have to be removed. If you want to delete points in a way that new border is smoothly following the curve of the shape you need some way to interpolate the shape border (based on the information of other points from the border). This interpolation have to pass trough two black points. Now, if you have interpolation you can calculate the interpolation curve between two black points and set to white all points right from the curve. I can suggest to use at least one more point from the curve and use some cubic spline interpolation.
EDIT:
Based on you comment.
Then the algorithm is simple: Keep a pointer that starts from lower point (A) and moves along the border (A') until it reaches the other point. This can be done by checking the neighbors of current pointer location and comparing colors. Now, when you pointer moves remove the line of red points from pointer (A') to line (blue) defined between to points A-B (in green). There is a pointer position when the row is the same as the other black point (e.g A' and B are on the same row). Then start a new pointer from B point in the same way tracing the border and remove the red pixels between two pointers A' and B'.
您需要从 A 到 B 画一条线,然后在其中一个红色区域开始洪水填充线右侧的像素。
You need to draw the line from A to B and then start a flood fill on one of the red pixels to the right of the line.