Find all the pixels in a row in Java

To qualify for this: let's say I have two specific pixels a and b, as well as a list of random others. Now I want to check all the pixels in this list if they are on a line that goes through a and b (but which is NOT limited to having a and b as endpoints!) I looked at the Bresenham line algorithm, but it seems they only find points between a and b? I also looked at linear equations in general, but I was kind of fixated on how to properly discrete a continuous line in pixels ...

(I'm trying to implement a random sampling algorithm in java that tries to find the row with the most pixels on it, if that matters).

Thanks so much for any help with this :)

+4
source share
2 answers

I highly recommend you calculate the distance between a point and a line .

If you use one pixel as a unit of measure (what will you do if you work in a pixel coordinate system), you can simply check if the distance from the point to the line is <1.

Here's how to calculate the distance between a point and a line:

+4
source

You can search not between a and b, but between points on the same line, but outside the borders of the image. You can make them simply overlay vector (ba) as many times as necessary on side and on side b. And use your Bresenham line algorithm.

For more specific answers, ask a better question, please. Do you think pixels are dots or squares or circles? What is a pixel on line in your terms? What width is your line? Are you looking for a line with a maximum number of pixels per cm length or within a rectangle? Among the lines you are looking for?

0
source

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


All Articles