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 › scanning pixels within shapes
Page Index Toggle Pages: 1
scanning pixels within shapes (Read 846 times)
scanning pixels within shapes
Aug 7th, 2009, 11:14pm
 
Hello all,

Just wanted to see if someone could point me in the right direction in regards to scanning pixels within a circle. Basically, I need to be able to scan a circle centered at some x and y with radius r to look to see if there is a certain specified color present within it.

I'm still learning how the index of pixels works, so this compounds my problem. I think there would be a way to do it with a TON of for loops, but I'm guessing this has been done before or is rather easy.

Thanks!
Re: scanning pixels within shapes
Reply #1 - Aug 8th, 2009, 1:28am
 
A simple, and perhaps naive way could be to loop over a square of side equals to the diameter of your circle. If dist() of rectangle point to the center is over the radius, don't check the pixel.
Re: scanning pixels within shapes
Reply #2 - Aug 8th, 2009, 11:31pm
 
That is quite clever. I agree, there has to be a more sophisticated way, but this is quite good. Definitely something I could muster.

Now to learn all about pixel indexing...
Re: scanning pixels within shapes
Reply #3 - Aug 10th, 2009, 2:18pm
 
pixel indexing is easy: pixels is a 1 dimension array generated simply placing one next to another every line of pixels of the image.

so ie. assuming you have a 200x200 image: pixels[0] will store the pixel with x=0 and y=0, pixels[10] the one @ x=0 and y=10, pixels[201] the one @ x=1 and y=1 and so on.

the quickest way to convert a position expressed in x,y format to pixels format is: x,y -> pixels[y*width+x]
Page Index Toggle Pages: 1