Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i find pixels points inside quadrilateral using Java?

Im doing some image processing and I have the coordinates of the 4 points of a quadrilateral. (something like a trapezium) How can i get the coordinates of all the pixels inside it? I'm using Java by the way. Thanks!

like image 945
orangebrainer Avatar asked Feb 05 '26 02:02

orangebrainer


1 Answers

You need scanline polygon filling.

Here's a quick PDF lecture on the subject:

http://www.cs.binghamton.edu/~reckert/460/lect11_2009-areafill-transformations.pdf

Here's a web page example with some sample C code and a good illustration of the basic idea:

http://alienryderflex.com/polygon_fill/

Here's the short form. Divide your quadrilateral lines into those that are on the left, and on the right. For each constant-Y-coordinate row, figure out the crossing point for the left line; figure out the crossing point for the right line; all pixels on that row between the two crossing points are inside of your trapezoid.

Just by way of history, this sort of thing was originally (and probably still is) done for rendering 3d scenes in software. I think it had a different name back then, but I can't remember it. However, you don't actually have to draw the pixels; the algorithm will give you the pixels whether you draw them or not.

like image 98
jprete Avatar answered Feb 13 '26 02:02

jprete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!