Do radial division on image from the centroid
9 views (last 30 days)
Show older comments

Hello,
I want to divide a binary image radially (in to 10 sections of 36 degrees each) and find the distance from the centroid to the middle of the perimeter of each of these sectors. So far I've found the centroid of the image as follows.
C = imread(filename);
bw = im2bw (C, graythresh(C)); % Threshhold each image
cc= bwconncomp (bw, 4); % The function bwconncomp finds all the connected componets in the binary image
celldata = regionprops(cc, 'centroid');
celldata_centroid = [celldata.Centroid];
I'm not quite sure what to do after this step. Please let me know if you have any suggestions. Thanks in advance
0 Comments
Accepted Answer
Image Analyst
on 22 Oct 2013
Edited: Image Analyst
on 22 Oct 2013
What I would do is to call bwboundaries() to get the perimeter locations.
boundaries = bwboundaries(binaryImage);
Then use the centroid to calculate both the angle and the distance from the centroid to every point along the perimeter. Something like (totally untested and off the top of my head!)
boundaryx = boundaries{:,2}
boundaryy = boundaries{:,1}
allDistances = sqrt((boundaryx-centroidx).^2 + (boundaryy-centroidy).^2);
allAngles = atand2(boundaryy./boundaryx);
Then examine that with min() to find the index and distance for every point you want, something like
[~, index36] = min(abs(allAngles - 36)); % Find index closest to 36 degrees
distance36 = distances(index36);
3 Comments
Image Analyst
on 2 Nov 2013
The error you got from
atan2(boundaryx./boundaryx);
was from your code, not mine. I did not use atan2. Nor did I do boundaryx./boundaryx which is just a vector of 1's since your numerator and denominator are the same. Besides, you aren't even doing anything with this mat_boundaries array that you created, at least not that I can see.
The help says "Each row in the matrix contains the row and column coordinates of a boundary pixel" So the first column has the rows (y values) of all the boundary pixels, and the second column has the columns (x values) of all the boundary pixels. That's why I took x from the second column. It's a common beginner mistake that functions return (x,y) and this is the same as (row, column). It is NOT. MATLAB has functions that work in both ways - some return (x,y) coordinates, and some return (row, column) coordinates and you have to be very watchful that you are matching the x with the column, and the y with the row, when you are mixing different ways of specifying coordinates.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!