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 › How to get average color of pixels from quad ?
Page Index Toggle Pages: 1
How to get average color of pixels from quad ?? (Read 2174 times)
How to get average color of pixels from quad ??
Nov 23rd, 2009, 4:39am
 
Hello
I'm trying to implement function which calculates average colour of pixels from quad area (not rectangle, not square).
How to design loop or loops which will go through all pixels of this area.

Quads examples:
http://img689.imageshack.us/img689/3622/image1b.jpg

http://img155.imageshack.us/img155/9430/image2qd.jpg



Re: How to get average color of pixels from quad ??
Reply #1 - Nov 23rd, 2009, 4:51am
 
using pixels you can get a pixel array holding all the color information of every pixel http://processing.org/reference/loadPixels_.html

now you can extract the red,green,blue etc. information http://processing.org/reference/red_.html summarize it and divide it through the total amount of pixels. now youve got your average red,green,blue that can be saved as a new color.

Re: How to get average color of pixels from quad ??
Reply #2 - Nov 23rd, 2009, 5:20am
 
hmm could You put here some simple implementation because i don't know how to "collect" pixels being inside that area.
It is simple when quad is a rectangle or a square but  if some flanks are not parallel ... it becomes complicated
Re: How to get average color of pixels from quad ??
Reply #3 - Nov 23rd, 2009, 5:32am
 
You can use the Java Polygon class.
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html
There is a method called contains(). Simply pass your coordinates and it returns true or false.

there is an also example in the hacks section : http://processing.org/hacks/hacks:using-awt-s-polygon-class-to-test-for-insideness?s=hacks%20class%20polygon
Re: How to get average color of pixels from quad ??
Reply #4 - Nov 23rd, 2009, 5:49am
 
Thank You it seams to be helpfull Wink
i have an idea how to use it.

I will thankfull if someone find another way to solve this problem

PEACE.
Re: How to get average color of pixels from quad ??
Reply #5 - Nov 23rd, 2009, 5:52am
 
another way would be to draw that polygon the way you did it right now (back/white) into a Pgrapics, and check both pixel arrays at the same time, and only add the color if the same pixel from the PGraphics is black...
Page Index Toggle Pages: 1