11 views (last 30 days)

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?

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.

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.

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
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;

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.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783535

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783535

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783538

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783538

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783541

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783541

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783544

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783544

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783546

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783546

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783550

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783550

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783794

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/499135-how-to-perform-shape-factor-analysis-circularity-on-list-of-x-y-coordinates#comment_783794

Sign in to comment.