Sometime you want to know if two objects have the same shape. For example, if you want to do lip reading, being able to compare mouth shapes is a pretty useful thing.
We can think of shapes as what left after we ignore rotation and scaling of objects.
We are going to see a simple way to compare shapes computationally and see how to use this way in Python and how to make the comparison faster using Numba.
Imagine two shapes that look the same, they might be of different sizes, or at different point of view orientation. But they are essentially the same. If we represent those shapes as point clouds, we can align those shapes by rotating and scaling the point clouds, such that points lay on top of each other.

If the objects are not the same, rotation and scaling won't perfectly align the points of the point cloud. We can say that the distance between the points after alignment is a measure of dissimilarity between shapes. This is the idea behind the [[procrustes distance]]
Scipy has a function to calculate the procrustes distance. It normalizes and aligns the input matrices and returns them along with the distance between the shapes.
from scipy.spatial import procrustes
x.shape # (N, 3)
y.shape # (N, 3)
x_, y_, dist = procrustes(x, y)
This is pretty fast, but what if you need to run this on many different shapes? In this case python function call overhead is going to cost you a lot of time.
Luckily we can overcome this by using numba and avoid the python overhead by compiling our function using nopython flag.
You can use a neural-net and embed shape information to some Euclidean space using and use distance in that space to make a comparison. There are other ways that are based on actually comparing the structure of what we are looking at.