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

조회 수: 6 (최근 30일)
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
  댓글 수: 7
Suhaas Garre
Suhaas Garre 2020년 1월 6일
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 2020년 1월 7일
편집: Suhaas Garre 2020년 1월 7일
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.
closed_tumor_3.jpg

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 1월 7일
편집: Adam Danz 2020년 1월 8일
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.
  댓글 수: 2
Suhaas Garre
Suhaas Garre 2020년 1월 8일
I will give that a try, thank you for all your help!
I'll update this post as I make progress.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Image Analyst
Image Analyst 2020년 1월 9일
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
Adam Danz
Adam Danz 2020년 1월 9일
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.

댓글을 달려면 로그인하십시오.


Meg Noah
Meg Noah 2020년 1월 6일
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;
colormap(gray);
axis equal
axis tight
plot(inY,inX,'color','w');
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);
imagesc(X1D,Y1D,imorig);
% 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
Suhaas Garre
Suhaas Garre 2020년 1월 7일
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.

댓글을 달려면 로그인하십시오.


Suhaas Garre
Suhaas Garre 2020년 1월 9일
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!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by