开发者

How to erase an area delimited by a line segment and a block of colors?

开发者 https://www.devze.com 2023-02-25 10:52 出处:网络
Given the picture below: The positi开发者_如何转开发on 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

Given the picture below:

How to erase an area delimited by a line segment and a block of colors?

The positi开发者_如何转开发on 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?


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'.

How to erase an area delimited by a line segment and a block of colors?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号