Calculate percentage of similarities in two polygons

조회 수: 8 (최근 30일)
Amaral
Amaral 2015년 11월 9일
편집: Amaral 2015년 11월 10일
Hello friends.
Is there any framework in Matlab that can calculate the percentage of similarities between two polygons?
If not, how can i implement one?
Googling i found out a formula to calculate the similarities of two polygons R and P2 using this formula:
But i don't know how to calculate the union and intersection polygons.
Any help please? :)
Thanks in advance!

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 11월 10일
If you have the Mapping Toolbox and want a more exact answer:
% Some example polygons
theta = linspace(0, 2*pi, 100);
x1 = cos(theta) - 0.5;
y1 = -sin(theta);
x2 = x1 + 1;
y2 = y1;
% Calculate
[xint, yint] = polybool('&', x1, y1, x2, y2);
[xun, yun] = polybool('|', x1, y1, x2, y2);
a1 = polyarea(xun, yun);
a2 = polyarea(xint, yint);
sim = 1 - (a1- a2)./a1;
  댓글 수: 1
Amaral
Amaral 2015년 11월 10일
편집: Amaral 2015년 11월 10일
It worked very well. It gives accurate results which is exactly what i'm looking for. Thanks :)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 11월 9일
If that definition works for you, then that's fine. One could think of others, but whatever works for what you need it to, is fine. I think the easiest way to solve the formula is to convert the polygons to images with poly2mask().
rows = 1920; % Whatever is needed to contain your points.
columns = 1600;
image1 = poly2mask(x1,y1, rows, columns);
image2 = poly2mask(x2,y2, rows, columns);
unionImage = image1 & image2;
intersectionImage = xor(image1, image2)
similarity - 1 - (sum(unionImage(:) - intersectionImage(:)) / sum(unionImage(:));
If your x and y are too small, then multiply them by some scaling factor beforehand, like 100 or 1000 or whatever so that your image is big and not too pixelated.
  댓글 수: 2
Amaral
Amaral 2015년 11월 9일
Thanks for the answer. :) I'll try it out :)
Amaral
Amaral 2015년 11월 9일
편집: Amaral 2015년 11월 9일
Your approach worked. But had to do some adjustments because i think the way you calculated the union and intersection is wrong. This way it gives the results i want, at least i think so according to the results in the tests :P
unionImage = image1 | image2;
intersectionImage = image1 & image2;
similarity = (1 - (sum(unionImage(:) - intersectionImage(:)) / sum(unionImage(:)))) * 100

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by