Changing values of all pixels within circle [Matlab]

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Larson, Moderators General, Prelates

Changing values of all pixels within circle [Matlab]

Postby Gunny » Thu May 17, 2012 7:29 am UTC

Hi,

In the attached picture, I have been able to detect a certain feature and denote it with a circle. However, I am kinda stuck on how can I find all the points within the circle and convert all pixels defined within the circle to a value of 0.

Image: http://img213.imageshack.us/img213/417/result2h.jpg

Would be great if someone can help me with this.

Cheers.
Gunny
 
Posts: 1
Joined: Sat Jul 18, 2009 11:11 pm UTC

Re: Changing values of all pixels within circle [Matlab]

Postby scarecrovv » Thu May 17, 2012 8:22 am UTC

A simple way would be to check if each pixel is within the radius of the circle of the center of the circle, and set them to 0. If you wanted to be more efficient, you could consider only the pixels within the square that fits around the circle.

Is there something that makes the problem more complex than this? Anything unclear?
User avatar
scarecrovv
 
Posts: 584
Joined: Wed Jul 30, 2008 4:09 pm UTC
Location: Massachusetts

Re: Changing values of all pixels within circle [Matlab]

Postby ConMan » Thu May 17, 2012 11:40 pm UTC

Are you trying to find something that's nice and matrix-y so that it works quickly in Matlab? Given that you've found the circle, am I right in saying that you have the radius and coordinates of the centre already calculated? In which case, consider the following (matrices are all of the same size and your image):

1. Create X where X[i, j] = i.
2. Create Y where Y[i, j] = j. (I'm pretty sure there are a few ways to create X and Y efficiently)
3. Create C by C = (X - x0) .^ 2 + (Y - y0) .^ 2, where (x0, y0) is the centre of your circle.
4. Create C1 by C1 = (C > r^2), where r is the radius of your circle.

So, what are the values in C1? What can you do with that and your pixel matrix?

If the dimensions of your matrices are quite big, then steps 3 and 4 may be a little prone to overflow errors, in which case changing C to ((X - x0) / r) .^2 + ((Y - y0) / r).^2 and C1 to (C > 1) should work a little better.
pollywog wrote:
Wikihow wrote:* Smile a lot! Give a gay girl a knowing "Hey, I'm a lesbian too!" smile.
I want to learn this smile, perfect it, and then go around smiling at lesbians and freaking them out.
User avatar
ConMan
 
Posts: 1190
Joined: Tue Jan 01, 2008 11:56 am UTC
Location: Where beer does flow, and men chunder.


Return to Computer Science

Who is online

Users browsing this forum: GuetraGma and 4 guests