Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the circle boundary

Tags:

matlab

I have a logical circular mask of 0 and 1 in my matrix which looks the following way.

Mask

What is the fastest way to get just the outside boundary in another matrix ?

Essentially I have to scan for the first 1 from left and first 1 from right in each row if there are duplicate 1's in the row ( there will be just one 1 in the topmost , bottommost points ).... Can someone help me in finding a fast way to do this ?

like image 511
anon Avatar asked Nov 05 '12 23:11

anon


People also ask

Which is the boundary of circle?

Definition. The distance around the boundary of a circle is called the circumference. The distance across a circle through the centre is called the diameter. The distance from the centre of a circle to any point on the boundary is called the radius.

What does having boundaries mean?

Provided by TherapistAid.com. Personal boundaries are the limits and rules we set for ourselves within relationships. A person with healthy boundaries can say “no” to others when they want to, but they are also comfortable opening themselves up to intimacy and close relationships.


2 Answers

You can use regionprops for that, here are a few examples that identify circles:

  • link1
  • link2
  • link3

or if you're sure there's only one circle and no noise, I assume you can just find the bottom/top/left/right edge and work from that:

m = loadcirclefunction();
pix_left  = find(any(m,1),1,'first');
pix_right = find(any(m,1),1,'last');
pix_top   = find(any(m,2),1,'first');
pix_bottom= find(any(m,2),1,'last');
like image 133
Gunther Struyf Avatar answered Oct 02 '22 13:10

Gunther Struyf


The other answers are good for finding general circles in images, but since you know that you're looking for a circle in a binary mask, bwmorph is probably your best bet.

I=imread('0ateM.png');
BW=im2bw(I);
BW2=bwmorph(BW,'endpoints');

image after bwmorph Edit: As I mentioned in the comments, in order to enlarge the circle so that you're getting the 0 pixels just outside the original circle mask set to 1 and everything else set to 0, you can invert the original mask and then use bwmorph:

WB=-(BW-1);
WB2=bwmorph(WB,'endpoints');

This has the unfortunate side-effect that the border of the image is changed to 1's. Of course you can easily change this. For an mxn image:

WB2(1,:)=0; WB2(:,1)=0; WB2(:,n)=0; WB2(m,:)=0;

An alternative approach is to directly use a filter on the original image:

f=[1 1 1; 1 -9 1; 1 1 1];
G=filter2(f,BW);
BW2=im2bw(G);

This will achieve the same results as WB2 above without the white border problem. The im2bw call is needed because after the filter the values are no longer just 0 or 1, they range somewhere between -8 and 8 and we want the negative values to be 0 and the positive values to be 1.

like image 40
beaker Avatar answered Oct 02 '22 13:10

beaker