How to scan a circle that is drawn over an image object?

A circle is drawn over a binary image object using plot. After this drawn I again want to scan this circle and want to store its circumference coordinates points to an array. How to do that?

4 Comments

Would it be acceptable to retrieve the handle of the line object created by plot and extract the data from there? Or is it required that you capture the axes as an image and do circle detection on the image?
I wonder if perhaps you should instead be using imellipse()
Actually I have taken small theta step size to draw a circle. So I am getting many coincidening points. Thats the reason I have plotted that circle over the binary image and then again want to store it's circumference coordinates to an array. In this way I will get individual coordinates
Quantize the coordinates to integers, and take the unique pairs. No drawing required. If you need them in order, you can use boundary() or you can subtract the centroid so that the points circle the centroid, and then convert to polar coordinates, and sort by angle.
I have got my unique points and this is forming a straight line . I am not getting any circle. How to resolve this ?

Sign in to comment.

 Accepted Answer

The form or size of the image below doesn't matter. It could be binary (with various irregularly shaped blobs in it), RGB, gray scale, whatever - it just doesn't matter.
Since you already have your (x,y) points of the "circle" (because you plotted them), if they're not already your circumference points (like it's a wiggly circle instead of a perfect circle), then you can fit a circle to what you have to get the "perfect" circle radius and center using the FAQ: https://matlab.wikia.com/wiki/FAQ#How_can_I_fit_a_circle_to_a_set_of_XY_data.3F
Now once you have the perfect circle, you can regenerate the perfect circle coordinates. Call round() on them if you want to quantize them to integer row, column values.

6 Comments

I totally don't understand this "I have got my unique points and this is forming a straight line . I am not getting any circle." How does this reconcile with this "A circle is drawn over a binary image object using plot." ?
Do you have a "circle" or a line? What does the image underneath what you plotted in the overlay have to do with anything?
Posting a picture/diagram/image would help. Use the green and brown frame icon.
x = int32(circleCenterX + r * sin(t));
y = int32(circleCenterY + r * cos(t));
x1=int32(unique(x));
y1=int32(unique(y));
plot(x1,y1,'r', 'LineWidth', 2);
I am using smaller theta step size thus getting coinciding points .For this I have used unique(). After that I am plotting those points on the image object. That is giving me a straight line instead of circle
Well, why are you calling unique()???? Don't do that. It just throws away half your values so you get a straight line!
t = linspace(0, 2*pi, 720);
circleCenterX = 50;
circleCenterY = 100;
r = 30
x = int32(circleCenterX + r * sin(t));
y = int32(circleCenterY + r * cos(t));
% x1=int32(unique(x));
% y1=int32(unique(y));
% plot(x1,y1,'r', 'LineWidth', 2);
plot(x,y,'r-', 'LineWidth', 2);
grid on;
well this is always giving me fixed no of points when considering theta. Actually I dont want this. I want to draw a circle over an binary image objects and want to store all(not fixed no of) its circumference coordinates pixels.
Actually when I am drawing 2 circles with two different radius but with same centers then using theta giving me some fixed no of points whatever the circle circumference is. This is actually I dont want. Circumference length will be different so no of points will differ. Is there any way do this?
The just call poly2mask() with your x,y coordinates, and get an image, then just call bwboundaries() on that image. Done. Simple.

Sign in to comment.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!