Takeshi
Takeshi

Reputation: 150

How to determine the points (pixels) that are within a given polygon inscribed in an image

Please consider the following scenario:

What I need then is to execute some process to all of the areas of the polygons, one pixel at a time. In my particular scenario, to 'sweep' the whole image pixel by pixel and verify if it's within any polygon, is not acceptable. Bonus: if a pixel has already been processed, but it's part of more than one polygon, do not process it again.

I was thinking that maybe I could, given any polygon and an image (arbitrary width x height), generate a list of pixels that are within the polygon's area. The problem then would be more of a math question, but I'm stuck. Other approaches are welcome too! Any ideas? Thanks a lot!

Upvotes: 0

Views: 1188

Answers (2)

rodamn
rodamn

Reputation: 2211

See Rasterizing a 2D polygon. In this case, instead of setting each pixel to particular color, you can execute your process on the specific pixel.

Upvotes: 1

azt
azt

Reputation: 2130

What you need is a polygon rasterizer, that gives all the pixels inside a polygon, e.g. http://alienryderflex.com/polygon_fill/

If you want to combine the polygons to factor out double pixels, then I'd suggest http://www.angusj.com/delphi/clipper.php

Compute the union of all the polygons and add them as positive and with non-zero-winding rule, or any other rule you want to post on your polygons (only relevant if they are self-overlapping).

Upvotes: 2

Related Questions