Very basic scoring to compare coordinates.
Module sppas.src.imgdata
Class sppasCoordsCompare
Description
Constructor
View Source
def __init__(self, coords1, coords2):
self.__coords1 = coords1
self.__coords2 = coords2
Public functions
compare_coords
Return a score on how image coordinates are similar.
Returns
- (float) value between 0. and 1. The highest the closer.
View Source
def compare_coords(self):
"""Return a score on how image coordinates are similar.
:return: (float) value between 0. and 1. The highest the closer.
"""
if self.__coords1 is None:
logging.error('Cant compare coordinates: coords1 is None')
return -1
if self.__coords2 is None:
logging.error('Cant compare coordinates: coords2 is None')
return -1
area1 = self.__coords1.area()
area2 = self.__coords2.area()
intersec = self.__coords1.intersection_area(self.__coords2)
return intersec / ((area1 + area2) / 2.0)
compare_areas
Return a score on how image areas are similar.
Returns
- (float) value between 0. and 1.
View Source
def compare_areas(self):
"""Return a score on how image areas are similar.
:return: (float) value between 0. and 1.
"""
area1 = self.__coords1.area()
area2 = self.__coords2.area()
min_area = min(area1, area2)
max_area = max(area1, area2)
if max_area < 2:
return 0.0
return float(min_area) / float(max_area)
compare_sizes
Return a score on how image sizes are similar.
Returns
- (float) value between 0. and 1.
View Source
def compare_sizes(self):
"""Return a score on how image sizes are similar.
:return: (float) value between 0. and 1.
"""
w_min = min(self.__coords1.w, self.__coords2.w)
w_max = max(self.__coords1.w, self.__coords2.w)
h_min = min(self.__coords1.h, self.__coords2.h)
h_max = max(self.__coords1.h, self.__coords2.h)
w_ratio = 0.0
if w_max > 2:
w_ratio = float(w_min) / float(w_max)
h_ratio = 0.0
if h_max > 2:
h_ratio = float(h_min) / float(h_max)
return (w_ratio + h_ratio) / 2.0