def calculateDimensions(self): #Calculate the minimum and maximum row and column of the region to determine its length and height min_row = int(min(self.row_locations)) max_row = int(max(self.row_locations)) min_col = int(min(self.col_locations)) max_col = int(max(self.col_locations)) #Update the region's length and height self.length = max_col - min_col self.height = max_row - min_row #Calculate region radius from length and height using Pythagoras theorem if self.length <= 0 or self.height <= 0: self.radius = 0 else: self.radius = basic_header.getHypotenuse(self.length, self.height)/2 self.area = self.length * self.height #Update the region's top corner position self.top_corner_position = (min_row, min_col) self.center_position = ( self.top_corner_position[0] + int(self.height/2), self.top_corner_position[1] + int(self.length/2) ) self.path = Path(self.top_corner_position[0], self.top_corner_position[1], self.row_locations, self.col_locations) self.mask[:] = 0 self.mask[ self.top_corner_position[0]:self.top_corner_position[0]+self.height, self.top_corner_position[1]:self.top_corner_position[1]+self.length ] = 255
def isSimilar(self, obj, margin=0.025): if obj == self: return True try: ratio_percentage_diff = getPercentageDifference( self.getLength2HeightRatio(), obj.getLength2HeightRatio(), max(self.row_length, self.col_length)) radius_percentage_diff = getPercentageDifference( self.radius, obj.radius, basic_header.getHypotenuse(self.col_length, self.row_length) / 2) if ratio_percentage_diff < 0 or radius_percentage_diff < 0: return False elif ratio_percentage_diff <= margin: if radius_percentage_diff <= margin: return True else: return False else: return False except ZeroDivisionError: return False
def _calculateRadius(self): #Calculate region radius from length and height using Pythagoras theorem self.radius = basic_header.getHypotenuse(self.length, self.height)/2