Loading autocnet/cg/cg.py +4 −13 Original line number Diff line number Diff line import json import ogr import pandas as pd from autocnet.fileio import io_gdal from scipy.spatial import ConvexHull Loading Loading @@ -65,16 +67,11 @@ def convex_hull(points): """ points.pixel_to_latlon() if isinstance(points, pd.DataFrame) : points = pd.DataFrame.as_matrix(points) hull = ConvexHull(points) coordinates = [[i,j] for (i, j) in hull.points] geom = {"type": "Polygon", "coordinates": [coordinates]} hull_poly = ogr.CreateGeometryFromJson(json.dumps(geom)) return hull_poly return hull def two_poly_overlap(poly1, poly2): """ Loading @@ -95,7 +92,7 @@ def two_poly_overlap(poly1, poly2): The ratio convex hull volume / ideal_area """ a_o = poly1.Intersection(poly2).GetArea() a_o = poly2.Intersection(poly1).GetArea() area1 = poly1.GetArea() area2 = poly2.GetArea() Loading @@ -103,9 +100,3 @@ def two_poly_overlap(poly1, poly2): overlap_percn = (a_o / (area1 + area2 - a_o)) * 100 overlap_info = [overlap_percn, overlap_area] return overlap_info def hull_overlap(poly1, poly2, convex_poly): a_o = poly1.Intersection(poly2) convex_overlap = convex_poly.Intersection(a_o) point_coverage = (convex_overlap.GetArea()/a_o.GetArea())*100 return point_coverage No newline at end of file autocnet/cg/tests/test_cg.py +13 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ sys.path.insert(0, os.path.abspath('..')) import numpy as np from .. import cg from osgeo import ogr class TestArea(unittest.TestCase): Loading @@ -19,3 +20,15 @@ class TestArea(unittest.TestCase): ratio = cg.convex_hull_ratio(self.pts, total_area) self.assertAlmostEqual(0.7566490, ratio, 5) def test_overlap(self): wkt1 = "POLYGON ((0 40, 40 40, 40 0, 0 0, 0 40))" wkt2 = "POLYGON ((20 60, 60 60, 60 20, 20 20, 20 60))" poly1 = ogr.CreateGeometryFromWkt(wkt1) poly2 = ogr.CreateGeometryFromWkt(wkt2) info = cg.two_poly_overlap(poly1, poly2) self.assertEqual(info[1], 400) self.assertEqual(info[0], 14.285714285714285) No newline at end of file autocnet/graph/edge.py +3 −6 Original line number Diff line number Diff line Loading @@ -423,11 +423,8 @@ class Edge(dict, MutableMapping): poly1 = self.source.geodata.footprint poly2 = self.destination.geodata.footprint self._overlapinfo = cg.two_poly_overlap(poly1, poly2) hull_poly = cg.convex_hull(self.source.get_keypoint_coordinates()) self._convex_overlap = cg.hull_overlap(poly1, poly2, hull_poly) overlapinfo = cg.two_poly_overlap(poly1, poly2) self.weight['overlap_area'] = self._overlapinfo[1] self.weight['overlap_percn'] = self._overlapinfo[0] self.weight['overlap_coverage'] = self._convex_overlap self.weight['overlap_area'] = overlapinfo[1] self.weight['overlap_percn'] = overlapinfo[0] autocnet/graph/network.py +7 −0 Original line number Diff line number Diff line Loading @@ -478,6 +478,13 @@ class CandidateGraph(nx.Graph): self.apply_func_to_edges('suppress', *args, **kwargs) def overlap(self, *args, **kwargs): ''' Compute the percentage and area coverage of two images See Also -------- autocnet.cg.cg.two_image_overlap ''' self.apply_func_to_edges('overlap') def minimum_spanning_tree(self): Loading autocnet/graph/node.py +19 −0 Original line number Diff line number Diff line from collections import MutableMapping import os import warnings import json import ogr import numpy as np import pandas as pd from scipy.misc import bytescale from scipy.spatial import ConvexHull from autocnet.cg import cg from autocnet.fileio.io_gdal import GeoDataset from autocnet.fileio import io_hdf from autocnet.matcher import feature_extractor as fe Loading Loading @@ -114,6 +118,20 @@ class Node(dict, MutableMapping): self._isis_serial = None return self._isis_serial def coverage(self): points = self.get_keypoint_coordinates() hull = cg.convex_hull(points) hull_area = hull.volume max_x = self.geodata.raster_size[0] max_y = self.geodata.raster_size[1] total_area = max_x * max_y self.coverage_area = hull_area/total_area return self.coverage_area def get_array(self, band=1): """ Get a band as a 32-bit numpy array Loading Loading @@ -343,3 +361,4 @@ class Node(dict, MutableMapping): mask = panel[clean_keys].all(axis=1) matches = self._keypoints[mask] return matches, mask Loading
autocnet/cg/cg.py +4 −13 Original line number Diff line number Diff line import json import ogr import pandas as pd from autocnet.fileio import io_gdal from scipy.spatial import ConvexHull Loading Loading @@ -65,16 +67,11 @@ def convex_hull(points): """ points.pixel_to_latlon() if isinstance(points, pd.DataFrame) : points = pd.DataFrame.as_matrix(points) hull = ConvexHull(points) coordinates = [[i,j] for (i, j) in hull.points] geom = {"type": "Polygon", "coordinates": [coordinates]} hull_poly = ogr.CreateGeometryFromJson(json.dumps(geom)) return hull_poly return hull def two_poly_overlap(poly1, poly2): """ Loading @@ -95,7 +92,7 @@ def two_poly_overlap(poly1, poly2): The ratio convex hull volume / ideal_area """ a_o = poly1.Intersection(poly2).GetArea() a_o = poly2.Intersection(poly1).GetArea() area1 = poly1.GetArea() area2 = poly2.GetArea() Loading @@ -103,9 +100,3 @@ def two_poly_overlap(poly1, poly2): overlap_percn = (a_o / (area1 + area2 - a_o)) * 100 overlap_info = [overlap_percn, overlap_area] return overlap_info def hull_overlap(poly1, poly2, convex_poly): a_o = poly1.Intersection(poly2) convex_overlap = convex_poly.Intersection(a_o) point_coverage = (convex_overlap.GetArea()/a_o.GetArea())*100 return point_coverage No newline at end of file
autocnet/cg/tests/test_cg.py +13 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ sys.path.insert(0, os.path.abspath('..')) import numpy as np from .. import cg from osgeo import ogr class TestArea(unittest.TestCase): Loading @@ -19,3 +20,15 @@ class TestArea(unittest.TestCase): ratio = cg.convex_hull_ratio(self.pts, total_area) self.assertAlmostEqual(0.7566490, ratio, 5) def test_overlap(self): wkt1 = "POLYGON ((0 40, 40 40, 40 0, 0 0, 0 40))" wkt2 = "POLYGON ((20 60, 60 60, 60 20, 20 20, 20 60))" poly1 = ogr.CreateGeometryFromWkt(wkt1) poly2 = ogr.CreateGeometryFromWkt(wkt2) info = cg.two_poly_overlap(poly1, poly2) self.assertEqual(info[1], 400) self.assertEqual(info[0], 14.285714285714285) No newline at end of file
autocnet/graph/edge.py +3 −6 Original line number Diff line number Diff line Loading @@ -423,11 +423,8 @@ class Edge(dict, MutableMapping): poly1 = self.source.geodata.footprint poly2 = self.destination.geodata.footprint self._overlapinfo = cg.two_poly_overlap(poly1, poly2) hull_poly = cg.convex_hull(self.source.get_keypoint_coordinates()) self._convex_overlap = cg.hull_overlap(poly1, poly2, hull_poly) overlapinfo = cg.two_poly_overlap(poly1, poly2) self.weight['overlap_area'] = self._overlapinfo[1] self.weight['overlap_percn'] = self._overlapinfo[0] self.weight['overlap_coverage'] = self._convex_overlap self.weight['overlap_area'] = overlapinfo[1] self.weight['overlap_percn'] = overlapinfo[0]
autocnet/graph/network.py +7 −0 Original line number Diff line number Diff line Loading @@ -478,6 +478,13 @@ class CandidateGraph(nx.Graph): self.apply_func_to_edges('suppress', *args, **kwargs) def overlap(self, *args, **kwargs): ''' Compute the percentage and area coverage of two images See Also -------- autocnet.cg.cg.two_image_overlap ''' self.apply_func_to_edges('overlap') def minimum_spanning_tree(self): Loading
autocnet/graph/node.py +19 −0 Original line number Diff line number Diff line from collections import MutableMapping import os import warnings import json import ogr import numpy as np import pandas as pd from scipy.misc import bytescale from scipy.spatial import ConvexHull from autocnet.cg import cg from autocnet.fileio.io_gdal import GeoDataset from autocnet.fileio import io_hdf from autocnet.matcher import feature_extractor as fe Loading Loading @@ -114,6 +118,20 @@ class Node(dict, MutableMapping): self._isis_serial = None return self._isis_serial def coverage(self): points = self.get_keypoint_coordinates() hull = cg.convex_hull(points) hull_area = hull.volume max_x = self.geodata.raster_size[0] max_y = self.geodata.raster_size[1] total_area = max_x * max_y self.coverage_area = hull_area/total_area return self.coverage_area def get_array(self, band=1): """ Get a band as a 32-bit numpy array Loading Loading @@ -343,3 +361,4 @@ class Node(dict, MutableMapping): mask = panel[clean_keys].all(axis=1) matches = self._keypoints[mask] return matches, mask