We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Pixels inside polygon
Page Index Toggle Pages: 1
Pixels inside polygon (Read 707 times)
Pixels inside polygon
Dec 20th, 2008, 3:24pm
 
Hi. Is there a way to get all the Pixels inside a triangle?

I need this to get the average color of a region (triangle) of an image.

thanks
Re: Pixels inside polygon
Reply #1 - Dec 21st, 2008, 6:19am
 
Depends on how fast you want this done.

Here is one way, but I'm sure there is a better solution. Use polygon's contains():

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Polygon.html
Re: Pixels inside polygon
Reply #2 - Dec 21st, 2008, 9:33am
 
i'd go about it this way:

- create a pgraphics object to fit your poly.
- background white
- fill black
- draw poly in
- loop pixels and if black you're in

edit:
see http://processing.org/hacks/hacks:picking_color_buffer

F
Re: Pixels inside polygon
Reply #3 - Dec 21st, 2008, 10:09am
 
Nice!  I think I'll use that.
Re: Pixels inside polygon
Reply #4 - Dec 22nd, 2008, 1:17am
 
Thank you very much!
Page Index Toggle Pages: 1