How to remove an area limited by a line segment and a block of colors?

Based on the picture below:

enter image description here

Position A and B are known, the rest of the image is only raw pixel data (only red and white pixels). What algorithm can I use to erase the part to the right of AB?

+4
source share
2 answers

The presence of two points determines the line. The line equation separates the pixels that need to be removed. If you want to delete points so that the new border follows the shape curve smoothly, you need to somehow interpolate the shape border (based on the information of other points from the border). This interpolation should go through two black dots. Now, if you have interpolation, you can calculate the interpolation curve between the two black points and set all the points to the right of the curve to white. I can suggest using at least one more point of the curve and use some cubic spline interpolation .

EDIT: Based on your comments.

Then the algorithm is simple: hold the pointer starting at the bottom point (A) and move along the border (A ') until you reach another point. This can be done by checking the neighboring locations of the current pointer and comparing the colors. Now, when you move the pointer, delete the line of red dots from the pointer (A ') to the line (blue) defined between the points AB (green). There is a pointer position when the line is the same as the other black dot (for example, A 'and B are on the same line). Then start the new pointer from point B in the same way as tracing the border and remove the red pixels between the two pointers A 'and B'.

enter image description here

+1
source

You need to draw a line from A to B, and then start the fill fill on one of the red pixels to the right of the line.

+1
source

Source: https://habr.com/ru/post/1347919/


All Articles