MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by CX
on 10 Nov 2013

I have the following binary image.

I need to divide this cell (the white section) into equal angle portions (of 36 degrees) at the centroid and find the distance from the centroid to the perimeter (edge of the white section) at each portion of angle. With the help of some of the answers I received in a previous post (courtesy of 'Image Analyst') I have the following code so far. ('some code portions have been changed from the original post marked with *')

C = imread('14.jpg'); bw = im2bw(C, graythresh(C)); cc = bwconncomp(bw, 4); celldata = regionprops(cc, 'centroid'); celldata_centroid = [celldata.Centroid]; centroidx = celldata_centroid(:, 1); centroidy = celldata_centroid(:, 2); boundaries = bwboundaries(C); mat_boundaries = cell2mat(boundaries); %* boundaryx = mat_boundaries(:, 2); boundaryy = mat_boundaries(:, 1); allDistances = sqrt((boundaryx - centroidx).^2 + (boundaryy - centroidy).^2); allAngles = atan2d(boundaryy, boundaryx); %* [~, index36] = min(abs(allAngles - 36)); % Find index closest to 36 degrees distance36 = distance(index36); %*

But I'm getting an error at the end saying not enough input arguments for the function 'distance'. Could someone help me out?

*No products are associated with this question.*

Answer by Image Analyst
on 10 Nov 2013

Accepted answer

You never defines distance. Maybe you meant allDistances instead?

CX
on 10 Nov 2013

Yes. Your correct. I thought you were calculating the distances using a function called distance. I just made that into allDistances. But I'm only getting one value. I'm guessing this is the distance from the centroid to the perimeter at 36 degrees? I actually need all lengths at intervals of 36 degrees. So that would be the radial distance at 36, 72, 108 etc... Any suggestions?

Image Analyst
on 10 Nov 2013

Once you read and understand the code, you'll realize that I give that to you. For every pixel around it I give you the angle and the distance. Maybe there is no pixel at exactly 72 degrees. Maybe there's one at 71.42 degrees, and another one at 72.894 degrees. I give you everything that's there. But I didn't stop there, I actually gave you an example of how to find the pixel nearest to 36 degrees, since there might not be one at exactly 36 degrees to the billionth decimal point. Are you starting to understand what I did now? Okay, so you just do that for every angle that you want. If you want, you can scan allAngles and pull out the ones that are closest to 36, 72, etc. See if you can do that on your own, following my example and putting it into a loop.

## 0 Comments