1

I created some MATLAB code, that find somes shapes in an image using regionpros and bwbounaries functions.

I have:

STATS = regionprops(L, 'all');

and from STATS I could easily find all my shapes Area and Perimeter. My problem is the following: I want to find the "square" shapes and I do in all shapes the following calculation 16 * area / (perimeter * perimeter), if this value is near one then I "may" have a square. But other shapes too like circles or rectangles are near one too. (Also some squares could be rotated in the image).

Is there a better way to distinguish the shapes (like circles, triangles ...)?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Johnathan Fr.
  • 11
  • 1
  • 3

1 Answers1

2

Matlab has a function

procrustes(X,Y)

which will compute distance between two shapes based on the types of transformations it would take to move the points defined by X onto the points defined by Y. For many shape classification tasks, minimizing this distance is a useful way of categorizing noisy instances of shapes. If your problem has 'perfect' shapes, this should work extremely well. Just have Y fixed as a perfect square, and any time that the linear transformation from X to Y is a pure scaling, then you know X is also a square. You could do some simple logical checking to select only shapes satisfying this sort of property.

ely
  • 74,674
  • 34
  • 147
  • 228
  • The Python package PyGeometry has a similar Procrustes optimization function if you're ever doing this stuff in Python. – ely Dec 22 '11 at 18:14