Commit e23f2556 authored by Adam Paquette's avatar Adam Paquette
Browse files

fixed merge conflicts

parents d02f5dfc 62ad00a7
Loading
Loading
Loading
Loading
+6 −30
Original line number Diff line number Diff line
import json
import ogr
import pandas as pd

from scipy.spatial import ConvexHull
@@ -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):

    """
@@ -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()
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -32,3 +32,4 @@ class TestArea(unittest.TestCase):

        self.assertEqual(info[1], 400)
        self.assertAlmostEqual(info[0], 14.285714285)
+0 −1
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ import warnings
import pvl
import os

from pysal.cg.shapes import Polygon
from autocnet.utils.utils import find_in_dict
from osgeo import ogr
import numpy as np
+2 −64
Original line number Diff line number Diff line
@@ -4,11 +4,8 @@ from collections import MutableMapping

import numpy as np
import pandas as pd
from pysal.cg.shapes import Polygon
from osgeo import ogr

from autocnet.cg.cg import convex_hull_ratio
from autocnet.cg.cg import overlapping_polygon_area
from autocnet.matcher import health
from autocnet.matcher import outlier_detector as od
from autocnet.matcher import suppression_funcs as spf
@@ -383,65 +380,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)

@@ -512,10 +450,10 @@ class Edge(dict, MutableMapping):
        destination_coordinates = self._construct_json_serial(destination_verts)

        if image == 'source':
            image_covered = source_points
            image_covered = source_verts
            node = self.source
        else:
            image_covered = destination_points
            image_covered = destination_verts
            node = self.destination

        convex_coordinates = self._construct_json_serial(image_covered)
+731 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading