Loading autocnet/cg/cg.py +6 −30 Original line number Diff line number Diff line import json import ogr import pandas as pd from scipy.spatial import ConvexHull Loading @@ -26,29 +24,6 @@ def convex_hull_ratio(points, ideal_area): return hull.volume / ideal_area def overlapping_polygon_area(polys): """ Parameters ---------- polys : list of polygon object with a __geo_interface__ Returns ------- area : float The area of the intersecting polygons """ geom = json.dumps(polys[0].__geo_interface__) intersection = ogr.CreateGeometryFromJson(geom) for p in polys[1:]: geom = json.dumps(p.__geo_interface__) geom = ogr.CreateGeometryFromJson(geom) intersection = intersection.Intersection(geom) area = intersection.GetArea() return area def convex_hull(points): """ Loading Loading @@ -88,9 +63,11 @@ def two_poly_overlap(poly1, poly2): Returns ------- overlap_info : list Percentage of overlap between the two images and the area that is being overlapped overlap_percn : float The percentage of image overlap overlap_area : float The total area of overalap """ a_o = poly2.Intersection(poly1).GetArea() Loading @@ -99,5 +76,4 @@ def two_poly_overlap(poly1, poly2): overlap_area = a_o overlap_percn = (a_o / (area1 + area2 - a_o)) * 100 overlap_info = [overlap_percn, overlap_area] return overlap_info return overlap_percn, overlap_area autocnet/cg/tests/test_cg.py +2 −1 Original line number Diff line number Diff line Loading @@ -32,3 +32,4 @@ class TestArea(unittest.TestCase): self.assertEqual(info[1], 400) self.assertAlmostEqual(info[0], 14.285714285) autocnet/graph/edge.py +1 −60 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import pandas as pd from pysal.cg.shapes import Polygon from autocnet.cg.cg import convex_hull_ratio from autocnet.cg.cg import overlapping_polygon_area from autocnet.cg import cg from autocnet.matcher import health from autocnet.matcher import outlier_detector as od from autocnet.matcher import suppression_funcs as spf Loading Loading @@ -381,65 +381,6 @@ class Edge(dict, MutableMapping): mask[mask] = self.suppression.mask self.masks = ('suppression', mask) def coverage_ratio(self, clean_keys=[]): """ Compute the ratio $area_{convexhull} / area_{imageoverlap}$. Returns ------- ratio : float The ratio $area_{convexhull} / area_{imageoverlap}$ """ if self.homography is None: raise AttributeError('A homography has not been computed. Unable to determine image overlap.') matches = self.matches # Build up a composite mask from all of the user specified masks matches, _ = self._clean(clean_keys) d_idx = matches['destination_idx'].values keypoints = self.destination.get_keypoint_coordinates(d_idx) if len(keypoints) < 3: raise ValueError('Convex hull computation requires at least 3 measures.') source_geom, proj_geom, ideal_area = self.compute_homography_overlap() ratio = convex_hull_ratio(keypoints, ideal_area) return ratio def compute_homography_overlap(self): """ Using the homography, estimate the overlapping area between images on the edge Returns ------- source_geom : object PySAL Polygon object of the source pixel bounding box projected_geom : object PySAL Polygon object of the destination geom projected into the source reference system using the current homography area : float The estimated area """ source_geom = self.source.geodata.pixel_polygon destination_geom = self.destination.geodata.pixel_polygon # Project using the homography vertices_to_project = destination_geom.vertices for i, v in enumerate(vertices_to_project): vertices_to_project[i] = tuple(np.array([v[0], v[1], 1]).dot(self.homography)[:2]) projected_geom = Polygon(vertices_to_project) # Estimate the overlapping area area = overlapping_polygon_area([source_geom, projected_geom]) return source_geom, projected_geom, area def plot(self, ax=None, clean_keys=[], **kwargs): return plot_edge(self, ax=ax, clean_keys=clean_keys, **kwargs) Loading Loading
autocnet/cg/cg.py +6 −30 Original line number Diff line number Diff line import json import ogr import pandas as pd from scipy.spatial import ConvexHull Loading @@ -26,29 +24,6 @@ def convex_hull_ratio(points, ideal_area): return hull.volume / ideal_area def overlapping_polygon_area(polys): """ Parameters ---------- polys : list of polygon object with a __geo_interface__ Returns ------- area : float The area of the intersecting polygons """ geom = json.dumps(polys[0].__geo_interface__) intersection = ogr.CreateGeometryFromJson(geom) for p in polys[1:]: geom = json.dumps(p.__geo_interface__) geom = ogr.CreateGeometryFromJson(geom) intersection = intersection.Intersection(geom) area = intersection.GetArea() return area def convex_hull(points): """ Loading Loading @@ -88,9 +63,11 @@ def two_poly_overlap(poly1, poly2): Returns ------- overlap_info : list Percentage of overlap between the two images and the area that is being overlapped overlap_percn : float The percentage of image overlap overlap_area : float The total area of overalap """ a_o = poly2.Intersection(poly1).GetArea() Loading @@ -99,5 +76,4 @@ def two_poly_overlap(poly1, poly2): overlap_area = a_o overlap_percn = (a_o / (area1 + area2 - a_o)) * 100 overlap_info = [overlap_percn, overlap_area] return overlap_info return overlap_percn, overlap_area
autocnet/cg/tests/test_cg.py +2 −1 Original line number Diff line number Diff line Loading @@ -32,3 +32,4 @@ class TestArea(unittest.TestCase): self.assertEqual(info[1], 400) self.assertAlmostEqual(info[0], 14.285714285)
autocnet/graph/edge.py +1 −60 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import pandas as pd from pysal.cg.shapes import Polygon from autocnet.cg.cg import convex_hull_ratio from autocnet.cg.cg import overlapping_polygon_area from autocnet.cg import cg from autocnet.matcher import health from autocnet.matcher import outlier_detector as od from autocnet.matcher import suppression_funcs as spf Loading Loading @@ -381,65 +381,6 @@ class Edge(dict, MutableMapping): mask[mask] = self.suppression.mask self.masks = ('suppression', mask) def coverage_ratio(self, clean_keys=[]): """ Compute the ratio $area_{convexhull} / area_{imageoverlap}$. Returns ------- ratio : float The ratio $area_{convexhull} / area_{imageoverlap}$ """ if self.homography is None: raise AttributeError('A homography has not been computed. Unable to determine image overlap.') matches = self.matches # Build up a composite mask from all of the user specified masks matches, _ = self._clean(clean_keys) d_idx = matches['destination_idx'].values keypoints = self.destination.get_keypoint_coordinates(d_idx) if len(keypoints) < 3: raise ValueError('Convex hull computation requires at least 3 measures.') source_geom, proj_geom, ideal_area = self.compute_homography_overlap() ratio = convex_hull_ratio(keypoints, ideal_area) return ratio def compute_homography_overlap(self): """ Using the homography, estimate the overlapping area between images on the edge Returns ------- source_geom : object PySAL Polygon object of the source pixel bounding box projected_geom : object PySAL Polygon object of the destination geom projected into the source reference system using the current homography area : float The estimated area """ source_geom = self.source.geodata.pixel_polygon destination_geom = self.destination.geodata.pixel_polygon # Project using the homography vertices_to_project = destination_geom.vertices for i, v in enumerate(vertices_to_project): vertices_to_project[i] = tuple(np.array([v[0], v[1], 1]).dot(self.homography)[:2]) projected_geom = Polygon(vertices_to_project) # Estimate the overlapping area area = overlapping_polygon_area([source_geom, projected_geom]) return source_geom, projected_geom, area def plot(self, ax=None, clean_keys=[], **kwargs): return plot_edge(self, ax=ax, clean_keys=clean_keys, **kwargs) Loading