Commit c8bc1e90 authored by jlaura's avatar jlaura
Browse files

Merge pull request #92 from kree/slope

Use slopes to refine fundamental matrix
parents f5d12b75 1b94d711
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
import unittest
import pandas as pd
import numpy as np

from .. import utils

class TestUtils(unittest.TestCase):
    def setUp(self):
        pass

    def test_slopes(self):
        x1 = pd.DataFrame({'x': np.arange(1, 11),
                           'y': np.arange(1, 11)})
        x2 = pd.DataFrame({'x': np.arange(6, 16),
                           'y': np.arange(11, 21)})

        slope = utils.calculate_slope(x1, x2)
        self.assertEqual(slope.slope[0], 2)
+21 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import tempfile
import os
import fnmatch
import numpy as np
import pandas as pd

def create_dir(basedir=''):
    """
@@ -34,3 +35,23 @@ def file_search(searchdir,searchstring):
            filelist.append(os.path.join(root, filename))
    filelist=np.array(filelist)
    return filelist    

def calculate_slope(x1, x2):
    """
    Calculates the 2-dimensional slope between the points in two dataframes each containing two columns ['x', 'y']
    The slope is calculated from x1 to x2.

    Parameters
    ----------
    x1 : dataframe
         Each row is a point with columns ['x', 'y']
    x2 : dataframe
        Each row is a point with columns ['x', 'y']

    Returns
    -------
    : dataframe
      A dataframe with the slope between the points in x1 and x2 for each row.
    """
    slopes = (x2.y.values - x1.y.values)/(x2.x.values-x1.x.values)
    return pd.DataFrame(slopes, columns=['slope'])
+0 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ import numpy.testing
import pandas as pd
from autocnet.transformation import transformations


class TestHomography(unittest.TestCase):

    def test_Homography(self):
+10 −4
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ class FundamentalMatrix(TransformationMatrix):
            compute this homography
    """

    def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, bin_id=0, **kwargs):
    def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, df=None, bin_id=0, **kwargs):
        """
        Refine the fundamental matrix by accepting some data classification
        method that accepts an ndarray and returns an object with a bins
@@ -192,6 +192,10 @@ class FundamentalMatrix(TransformationMatrix):
        method : object
                 A function that accepts and ndarray and returns an object
                 with a bins attribute

        df      : dataframe
                Dataframe (from which a ndarray will be extracted) to pass to the method.

        bin_id : int
                 The index into the bins object.  Data classified > this
                 id is masked
@@ -209,10 +213,12 @@ class FundamentalMatrix(TransformationMatrix):
               data in the new fundamental matrix.
        """
        # Perform the data classification
        fj = method(self.error.values.ravel(), **kwargs)
        if df is None:
            df = self.error
        fj = method(df.values.ravel(), **kwargs)
        bins = fj.bins
        # Mask the data that falls outside the provided bins
        mask = self.error['Reprojection Error'] <= bins[bin_id]
        mask = df.iloc[:, 0] <= bins[bin_id]
        new_x1 = self.x1.iloc[mask[mask == True].index]
        new_x2 = self.x2.iloc[mask[mask == True].index]
        fmatrix, new_mask = compute_fundamental_matrix(new_x1.values, new_x2.values)
@@ -220,7 +226,7 @@ class FundamentalMatrix(TransformationMatrix):

        # Update the current state
        self[:] = fmatrix
        self.mask[self.mask == True] = mask
        self.mask = mask

        # Update the action stack
        try:
+1028 −0

File added.

Preview size limit exceeded, changes collapsed.