How to find greatest and smallest diameter of an irregular shape

I have an irregular shape in which I need to find the Greatest diameter and the smallest diameter.
Greatest diameter(GD): is The length of the line which connects the two farthest boundary points and passes across the lesion centroid (C), which is given by:
where n is the number of pixels inside the lesion, and (xi, yi) is the coordinates of the i-th lesion pixel.
Shortest Diameter (SD): The length of the line which connects the two nearest boundary points and passes across the lesion centroid.
I used regionprops to find out the centroid and equidiameter. How do I find the greatest and smallest diameter? Please help with the code.
Thank You.

4 Comments

How do you want to handle discretization? Your (xi,yi) are at discrete integer locations whereas the centroid is not. It is therefore almost impossible that two pairs of (discrete) boundary points will ever be co-linear with the centroid.
Can't I round off the centroid? If not, How do I proceed? Is equivdiameter not the right way to go about it?
From the regionprops documentation, equivdiameter gives the diameter of a circle with the same area as the region . I don't see any direct relationship between that and what you define as SD and GD.
You have defined a shape property that regionprops does not seem to handle. You must complete the definitions to that we all know how to compute it. Rounding the centroid won't ensure colinearity with any of the other pairs of points.
Okay I tried another method. I traced all the boundary points of my shape using bwboundaries
This gives me an array of all the boundary points. Now, can I use euclidean distance to determind the smallest and largest distance for the points? I can run a for loop and determine the distance between the points maybe? Is this correct? I am confused as to how to run a for loop for determining the distance for the boundary points.
If that's the right approach, how to code it? Please guide.

Sign in to comment.

 Accepted Answer

The problem is, because youre image is digitized, there will be cases where no pixel lies on a line with the other two pixels, so you have to find the closest.
Find the centroid with regionprops. The equivDiameter doesn't matter.
Then find the boundaries with bwboundaries().
For each point on the boundary...
Those two points define a line.
For all other points, use the point-to-line formula to find the point on the other side that has the minimum point-to-line distance.
Compute the distance from that third point to the first point, keeping track of if it's the max or min length encountered so far.
It's not hard but will take a bit of programming, maybe a half hour or so. Give it a try.

6 Comments

binaryImage=imread('001.jpg');
% Label each blob so we can make measurements of it
labeledImage = bwlabel(binaryImage);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'Centroid');
% Get the centroid.
centroidX = blobMeasurements(1).Centroid(1);
centroidY = blobMeasurements(1).Centroid(2);
% Get the boundary.
boundaries = bwboundaries(binaryImage);
thisBoundary = boundaries{1};
% Get the distances of the boundary pixels from the centroid.
distances = sqrt((thisBoundary(:,1) - centroidX).^2 + (thisBoundary(:,2) - centroidY).^2);
% Scan the boundary to find the pixel on
% it that is farthest from the centroid.
maxRadius = max(distances);
GD=2*maxRadius; % greatest diameter
minRadius=min(distances);
SD=2*minRadius; % shortest diameter
l don't know if the following code is right. Please look and verify.
No, that's not correct AT ALL . For many reasons.
You'll need to follow the algorithm I showed you.
I did not understand your algorithm and the code I suggested seems to give me what I need.
Could you please point out what is wrong with the code? Could you also explain this part of the algorithm you suggested.
*For each point on the boundary...
Those two points define a line.
For all other points, use the point-to-line formula to find the point on the other side that has the minimum point-to-line distance.
Compute the distance from that third point to the first point, keeping track of if it's the max or min length encountered so far.*
I don't understand what you mean why "point on the other side that has the minimum point to line distance."
I used the Euclidian distance formula to get the distances of all points from the centroid. Then I took the max distance which gave me the maximum radius. I used this to find maximum diameter. Which is what I wanted.
Please tell me where I am going wrong in my code and please explain your algorithm further.
Thank You.
I'm going to make an extreme example just to illustrate the point. If I took something more compact and round, you might not realize why your algorithm won't work.
Look at the figure below, where you have a big lesion with a small tendril going out from it. C is the centroid - not much different than the center because the small tendril does not have much area and does not pull the centroid much towards point D. What you want to find is the distances BD and EF.
What your algorithm does is to find the max distance, which would be CD, then double it to get the diameter. Well, that would essentially be the distance AD, which is far more than the distance BD. So you can't do that. You need to find point B. Point B is on the other side of point C than point D is. But points D and C form a perfect line whereas the boundary points around point b take on only integer values since they must lie on the pixel grid. What if you wanted a point x=200.45 but you had only coordinates 200 and 201 there (because they must be integer locations of pixels)? It wouldn't find 200.45. So you must find the closest one. And x=200 would be the closest since it's only 0.45 away from 200.45 while the next pixel over is 0.55 away at x=201.
By the way, one might be tempted to think that the Euclidean Distance Transform, done by bwdist(), could help, but it won't, because the peak of the EDT is not at the centroid. For this blob, it would be slightly above point C.
Oh! Now I understand. My radius part is right. But when I double the radius, the diameter may either exceed/fall short of the lesion area. Since my lesion is not a perfect circle, twice the radius is not equal to the diameter of the lesion like you have shown in your example.
But I still have a doubt in the algorithm you have suggested. I run a for loop for all the boundary points that form a line passing through the centroid. After this, you want me to find the minimum point to line distance. I do not understand this. Could you maybe phrase it in a simpler way so that I can code it up. Also what is the "third point"? and if possible, could you guide me with the code too (not the whole code, just enough to help me do it on my own)
Thank You so much for your clear explanation. I have attached my image I am working on for your reference. It is a skin lesion image.
I'm working on something but I'm not done yet. It's taking a lot of time. Attached is a partially working version. I'll work more on it tomorrow and delete this one if I can get an update.
Actually I hesitate to upload it because you'll say it doesn't work. I know it doesn't work yet, but if you want to try to finish it yourself, go ahead.

Sign in to comment.

More Answers (2)

Hello dear,
I had also come to your issue. The solution that I came up with is to detect all the boundary elements, and also identify the centroid of the shape. Now choose every possible pair of boundary elements and check it for its collinearity with the centroid (I opted for PCA here). That may help to filter out the largest and smallest diameter. But the issue is its computational load . . . so can anyone suggest me a faster approach to perform it?
Abshaya N
Abshaya N on 25 Mar 2017
Edited: Abshaya N on 25 Mar 2017
Can anyone give me the java code to find the largest and smallest diameter for the labeled objects in an image please....... I use bounding box but its not work well for the irregular shapes.

3 Comments

Define diameter. Do you mean the Equivalent Circular Diameter, or the Feret diameter? And what is the min diameter? Is it the minimum of the max diameters of all the blobs? Because the min diameter could be the distance between two points on a given blob which would just be 1. Or do you mean the min diameter is the min perpendicular distance? See attached demo.
Sorry, may I know the reference or journal from the above program code. Thank you, sorry for my bad english
Hi, were you able to solve it, i have to write this in C#, request you direct me to the algorithm. Thanks!

Sign in to comment.

Categories

Find more on Particle & Nuclear Physics 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!