-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added polygon filter method to reduce number of polygon given gven fr…
…om SAM predictions. (#142)
- Loading branch information
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import json | ||
import math | ||
|
||
class NearNeighborRemover: | ||
def __init__(self,distance_threshold): | ||
self.distance_threshold = distance_threshold | ||
|
||
def calculate_distance(self, point1, point2): | ||
x1, y1 = point1 | ||
x2, y2 = point2 | ||
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) | ||
|
||
def remove_near_neighbors(self, points): | ||
filtered_points = [points[0]] # Add the first point to the filtered list | ||
for i in range(1, len(points)): | ||
# Calculate the distance between the current point and the last added point | ||
distance = self.calculate_distance(points[i], filtered_points[-1]) | ||
# If the distance is above the threshold, add the current point to the filtered list | ||
if distance >= self.distance_threshold: | ||
filtered_points.append(points[i]) | ||
return filtered_points | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters