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

source share