forked from pysal/pointpats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed mbr to minimum_bounding_rectangle, Added opencv minimum_area_rectangle, Removed loop in mbr and substituted with in-built max and min functions
- Loading branch information
Showing
3 changed files
with
45 additions
and
16 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
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
""" | ||
|
||
__author__ = "Serge Rey [email protected]" | ||
__all__ = ['mbr', 'hull', 'mean_center', 'weighted_mean_center', | ||
__all__ = ['minimum_area_rectangle', 'minimum_bounding_rectangle', 'hull', 'mean_center', 'weighted_mean_center', | ||
'manhattan_median', 'std_distance', 'euclidean_median', 'ellipse', | ||
'skyum', 'dtot',"_circle"] | ||
|
||
|
@@ -18,6 +18,7 @@ | |
import numpy as np | ||
import warnings | ||
import copy | ||
import cv2 as cv | ||
from math import pi as PI | ||
from scipy.spatial import ConvexHull | ||
from libpysal.cg import get_angle_between, Ray, is_clockwise | ||
|
@@ -27,10 +28,36 @@ | |
not_clockwise = lambda x: not is_clockwise(x) | ||
|
||
MAXD = sys.float_info.max | ||
MIND = sys.float_info.min | ||
MIND = sys.float_info.minz | ||
|
||
def minimum_area_rectangle(points): | ||
""" | ||
Find minimum area rectangle of a point array. | ||
Parameters | ||
---------- | ||
points : arraylike | ||
(n,2), (x,y) coordinates of a series of event points. | ||
Returns | ||
------- | ||
min_x : float | ||
leftmost value of the vertices of minimum bounding rectangle. | ||
min_y : float | ||
downmost value of the vertices of minimum bounding rectangle. | ||
max_x : float | ||
rightmost value of the vertices of minimum bounding rectangle. | ||
max_y : float | ||
upmost value of the vertices of minimum bounding rectangle. | ||
""" | ||
points = np.array(points) | ||
points = np.float32(points[:, np.newaxis, :]) | ||
rect = cv.minAreaRect(points) | ||
min_x, min_y, max_x, max_y = cv.boxPoints(rect) | ||
return min_x, min_y, max_x, max_y | ||
|
||
def mbr(points): | ||
def minimum_bounding_rectangle(points): | ||
""" | ||
Find minimum bounding rectangle of a point array. | ||
|
@@ -54,16 +81,11 @@ def mbr(points): | |
points = np.asarray(points) | ||
min_x = min_y = MAXD | ||
max_x = max_y = MIND | ||
for point in points: | ||
x, y = point | ||
if x > max_x: | ||
max_x = x | ||
if x < min_x: | ||
min_x = x | ||
if y > max_y: | ||
max_y = y | ||
if y < min_y: | ||
min_y = y | ||
x, y = zip(*points) | ||
min_x = min(x) | ||
min_y = min(y) | ||
max_x = max(x) | ||
max_y = max(y) | ||
return min_x, min_y, max_x, max_y | ||
|
||
|
||
|
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