Reputation: 43
How to compare two black curves on a white background? How to do it as fast? For example this
and this
are similar, but this
and this
are not
First curve I'll draw on JPanel, second is image.
Upvotes: 3
Views: 691
Reputation: 6365
For each point of curve1 find nearest point on curve2, calculate maximal or average distance. Then swap curves, repeat and take maximal result.
If you want to take direction into account - use modified distance function which includes comparison of directions.
Upvotes: 1
Reputation: 11098
I have an idea. Not sure that it is the best one, but somehow it allows to evaluate the coefficient of similarity of two cruves.
Lets make a matrix for each cruve putting 1 for black pixels and 0 for white ones. Now if we want to compare two cruves with matrixes a
and b
at first we should construct third matrix c
where:
if(a[i][j] == 0 && b[i][j] == 0)
c[i][j] = 0;
else if(a[i][j] == 0 || b[i][j] == 0)
c[i][j] = 1;
else
c[i][j] = 2;
Then we will denote by S
count of cells where c[i][j] != 0
, and by T
count of cells where c[i][j] == 2
. And at last two cruves are similar if T / S > 1 - eps
, where eps
you should choose yourself according what accuracy you want to get.
Upvotes: 4
Reputation: 66156
This algorithm is not very accurate. You'll probably have to make additional analysis like:
Upvotes: 0