MATLAB Answers

How to perform shape factor analysis (circularity) on list of x, y coordinates

11 views (last 30 days)
Suhaas Garre
Suhaas Garre on 6 Jan 2020
Commented: Adam Danz on 9 Jan 2020
I have a list of x-y coordinates corresponding to the points along the perimeter of a shape. MATLAB's Image Processing Toolbox seems to allow for shape factor analysis of closed shapes within binary images, but I don't have enough points to fully close the shape.
So far, I've just plotted the x-y coordinates, but I'm having difficulty analyzing further. Are there built in mathematical methods for calculating max/min feret diameter and circularity using just a set of points?
Alternatively, are there other methods in image processing that are generally used to analyze shapes described by individual points?closed_tumor_1.jpg


Show 4 older comments
Adam Danz
Adam Danz on 6 Jan 2020
"I am mainly trying to find ways to quantify the difference between more elongated shapes vs shapes with a more square-like aspect ratio."
It sounds to me like you'll need to compute the length of the major and minor axes. If those two values are close to each other you can classify the object as a square-ish-blob. Otherwise you'd classify it as not-square-ish (note that it could be oblong, curved, u-shaped, etc).
If you're missing a big chunk of coordinates such as an entire side of the object, it may be obvious whether the object is square-ish or not. For example, we can assume the incomplete object below is not square-ish
but we cannot make the same assumption with this object
Perhaps sharing some examples may inspire more suggestions.
Suhaas Garre
Suhaas Garre on 6 Jan 2020
Yes, I certainly see what you mean. I’ll post some scatter plots tomorrow with some examples of what I’m referring to.
Thanks for your help so far!
Suhaas Garre
Suhaas Garre on 7 Jan 2020
I've updated the original question with an example of what I'm working with. I managed to close the shape yesterday, but as you can see, it is highly irregular. I've attached another example onto this comment as well.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 7 Jan 2020
Edited: Adam Danz on 8 Jan 2020
It looks like you're working with binary images in which case, you could use regionprops() along with the 'MajorAxisLength' and 'MinorAxisLength' properties to get the 'length' and 'width' of each blob. If those values are close to each other they can be categorized as square-ish. You'll have to choose a threshold such as
isSquareish = MinorAxisLength/MajorAxisLength > 0.95;
If you decide to go this route and get stuck, feel free to update us with your code so we can stay involved.

More Answers (3)

Image Analyst
Image Analyst on 9 Jan 2020
There is a new function bwferet() that you might want to look into. You might want to look into edge linking algorithms to close the shapes.
A circle could have the same major and minor axis lengths. I've found that looking at circularities (perimeter squared divided by 4*pi*area) or feret diameters is not that great a way but it could be one factor in the decision if a blob is square. One of the more reliable ways to find a square is to find the centroid of the points and then get the distances of all perimeter points to the centroid, then plot that and look for 4 peaks. Attached is my demo for shape recognition where I do that for a variety of polygons.
0000 Screenshot.png

  1 Comment

Adam Danz
Adam Danz on 9 Jan 2020
This is great.
BTW, I was assuming the OP wanted to classify elongated blobs from blobs without an obviously longer axis (hense the term square-ish). If the task is to identify shapes that are nearly square, then my simple minor/major axis idea isn't robust enough.

Sign in to comment.

Meg Noah
Meg Noah on 6 Jan 2020
For the final part of your question, 'Alternatively, are there other methods in image processing that are generally used to analyze shapes described by individual points?' one way is to raserize the data. This isn't a great way, but it gives ok results depending on the X, Y range and the accuracy you need:
% let inY and inX be your vectors <shapename>.Y, <shapename>.X
itheta = 0:360;
% fake data is a circle of radius R
R = 10.0;
inY = R.*sind(itheta); inX = R.*cosd(itheta);
h1 = figure(1);
gridDensity = 0.05; X1D = -2*R:gridDensity:2*R; Y1D = -2*R:gridDensity:2*R';
nX = numel(X1D); nY = numel(Y1D);
imagesc(X1D,Y1D,zeros(nY,nX),[0 255]);
set(h1,'position',[1 1 1000 800]);
set(gca,'units','pixels','position',[5 5 nX nY],'visible','off');
hold on;
axis equal
axis tight
tim = getframe(gca);
imorig = tim.cdata(:,:,1);
imorig(imorig>0) = 1;
% Note: If your data are in latitude/longitude values
% then use vec2mtx to rasterize it
% rasterize the data values at grid size = 0.25
% gridDensity = 1/2; X1D = -2*R:0.25:2*R; Y1D = -2*R:0.25:2*R';
% [X2D,Y2D] = meshgrid(X1D,Y1D);
% [img, inRefVec] = vec2mtx(inY, inX, gridDensity);
% verify
h2 = figure(2);
% apply standard blob detection and characterization
imblob = bwlabel(imorig,8);
stats = regionprops(imblob,'ALL');
diameterInPixels = norm(stats.BoundingBox([1 3]) - stats.Centroid);
diameterInDistance = diameterInPixels*gridDensity;
fprintf(1,'Diameter in Distance: %f\n',diameterInDistance);
The output is 10.015 whereas the input radius was 10.
If your data X, Y are latitude and longitude, then use the vec2mtx matlab command to rasterize.

  1 Comment

Suhaas Garre
Suhaas Garre on 7 Jan 2020
Hi Meg,
Thanks for your response! I actually got the points to fully close the shape so that doesn't appear to be an issue anymore, thankfully.

Sign in to comment.

Suhaas Garre
Suhaas Garre on 9 Jan 2020
As an update, I managed to close the shape, convert to greyscale, and binarize it.
I'm having some problems with the data itself (unrelated to MATLAB) so I will need to figure those out before I move along any further.
@Image Analyst: Thank you for the suggestions, I will give that a try once I get the rest working as well.
Thank you all for your help!


Sign in to comment.

Sign in to answer this question.