Commit 7abe22d4 authored by jlaura's avatar jlaura Committed by GitHub
Browse files

Updates subpixel API and warning fixes (#268)

* Homogenize the subpixel API and fix/suppress warnings in tests

* Fixes subpixel for edge case where FFT is 0

* Weird init issue causing tests to fail?

* missed a debugging print

* Fixes dtype in ring_matcher dynamic growth

* Thanks @Kelvinrr debug print

* Fixes for networkx 2.3 improvements to subclassing

* Travis precision differs from macbook

* typo

* typo
parent 52360416
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
import os
import warnings

import autocnet
from pkg_resources import get_distribution, DistributionNotFound

import autocnet
import autocnet.examples
import autocnet.camera
import autocnet.cg
@@ -12,7 +13,6 @@ import autocnet.matcher
import autocnet.transformation
import autocnet.utils

from pkg_resources import get_distribution, DistributionNotFound
try:
    _dist = get_distribution('autocnet')
    # Normalize case for Windows systems
+15 −15
Original line number Diff line number Diff line
@@ -54,22 +54,22 @@ class TestArea(unittest.TestCase):
        intersection = Polygon([(10, 5), (20, 5), (20, 20), (10, 20)])

        voronoi_gdf = cg.compute_voronoi(keypoints)
        self.assertAlmostEquals(voronoi_gdf.weight[0], 12.0)
        self.assertAlmostEquals(voronoi_gdf.weight[1], 13.5)
        self.assertAlmostEquals(voronoi_gdf.weight[2], 7.5)
        self.assertAlmostEquals(voronoi_gdf.weight[3], 7.5)
        self.assertAlmostEquals(voronoi_gdf.weight[4], 13.5)
        self.assertAlmostEqual(voronoi_gdf.weight[0], 12.0)
        self.assertAlmostEqual(voronoi_gdf.weight[1], 13.5)
        self.assertAlmostEqual(voronoi_gdf.weight[2], 7.5)
        self.assertAlmostEqual(voronoi_gdf.weight[3], 7.5)
        self.assertAlmostEqual(voronoi_gdf.weight[4], 13.5)

        voronoi_gdf = cg.compute_voronoi(keypoints, geometry=True)
        self.assertAlmostEquals(voronoi_gdf.geometry[0].area, 12.0)
        self.assertAlmostEquals(voronoi_gdf.geometry[1].area, 13.5)
        self.assertAlmostEquals(voronoi_gdf.geometry[2].area, 7.5)
        self.assertAlmostEquals(voronoi_gdf.geometry[3].area, 7.5)
        self.assertAlmostEquals(voronoi_gdf.geometry[4].area, 13.5)
        self.assertAlmostEqual(voronoi_gdf.geometry[0].area, 12.0)
        self.assertAlmostEqual(voronoi_gdf.geometry[1].area, 13.5)
        self.assertAlmostEqual(voronoi_gdf.geometry[2].area, 7.5)
        self.assertAlmostEqual(voronoi_gdf.geometry[3].area, 7.5)
        self.assertAlmostEqual(voronoi_gdf.geometry[4].area, 13.5)

        voronoi_inter_gdf = cg.compute_voronoi(keypoints, intersection)
        self.assertAlmostEquals(voronoi_inter_gdf.weight[0], 22.5)
        self.assertAlmostEquals(voronoi_inter_gdf.weight[1], 26.25)
        self.assertAlmostEquals(voronoi_inter_gdf.weight[2], 37.5)
        self.assertAlmostEquals(voronoi_inter_gdf.weight[3], 37.5)
        self.assertAlmostEquals(voronoi_inter_gdf.weight[4], 26.25)
        self.assertAlmostEqual(voronoi_inter_gdf.weight[0], 22.5)
        self.assertAlmostEqual(voronoi_inter_gdf.weight[1], 26.25)
        self.assertAlmostEqual(voronoi_inter_gdf.weight[2], 37.5)
        self.assertAlmostEqual(voronoi_inter_gdf.weight[3], 37.5)
        self.assertAlmostEqual(voronoi_inter_gdf.weight[4], 26.25)
+22 −37
Original line number Diff line number Diff line
@@ -428,18 +428,13 @@ class Edge(dict, MutableMapping):
                     for subpixel accuracy

        template_size : int
                        The size of the template in pixels, must be odd
                        The size of the template in pixels, must be odd. If using phase, 
                        only the template size is used.

        search_size : int
                      The size of the search
                      The size of the search area. When method='template', this size should
                      be >= the template size

        max_x_shift : float
                      The maximum (positive) value that a pixel can shift in the x direction
                      without being considered an outlier

        max_y_shift : float
                      The maximum (positive) value that a pixel can shift in the y direction
                      without being considered an outlier
        """
        # Build up a composite mask from all of the user specified masks
        matches, mask = self.clean(clean_keys)
@@ -450,11 +445,12 @@ class Edge(dict, MutableMapping):

        # Determine which algorithm is going ot be used.
        if method == 'phase':
            func = sp.subpixel_phase
            shifts_x, shifts_y, strengths, new_x, new_y = sp._prep_subpixel(len(matches), 2)
            func = sp.iterative_phase
            nstrengths = 2
        elif method == 'template':
            func = sp.subpixel_template
            shifts_x, shifts_y, strengths, new_x, new_y = sp._prep_subpixel(len(matches), 1)
            nstrengths = 1
        shifts_x, shifts_y, strengths, new_x, new_y = sp._prep_subpixel(len(matches), nstrengths)

        # for each edge, calculate this for each keypoint pair
        for i, (idx, row) in enumerate(matches.iterrows()):
@@ -477,31 +473,20 @@ class Edge(dict, MutableMapping):
                dx = d_keypoint.x
                dy = d_keypoint.y

            s_template, _, _ = sp.clip_roi(s_img, sx, sy,
                                     size_x=template_size, size_y=template_size)
            d_search, dxr, dyr = sp.clip_roi(d_img, dx, dy,
                                   size_x=search_size, size_y=search_size)
            
            # Now check to see if these are the same size.
            if method == 'phase' and (s_template.shape != d_search.shape):
                s_size = s_template.shape
                d_size = d_search.shape
                updated_size = int(min(s_size + d_size) / 2)
                s_template, _, _ = sp.clip_roi(s_img, sx, sy,
                                     size_x=updated_size, size_y=updated_size)
                d_search, dxr, dyr = sp.clip_roi(d_img, dx, dy,
                                    size_x=updated_size, size_y=updated_size)         
            shift_x, shift_y, metrics = func(s_template, d_search, **kwargs)

            # ROIs and clipping all work using whole pixels. The clip_roi func returns
            # the subpixel components that are lost when converting to whole pixels
            # reapply those here.
            shifts_x[i] = shift_x + dxr
            shifts_y[i] = shift_y + dyr

            new_x[i] = dx - shift_x
            new_y[i] = dy - shift_y
            strengths[i] = metrics
            if method == 'phase':
                res = sp.iterative_phase(sx, sy, dx, dy, s_img, d_img, size=template_size, **kwargs)
                if res[0]:
                    new_x[i] = res[0]
                    new_y[i] = res[1]
                    strengths[i] = res[2]
            elif method == 'template':
                new_x[i], new_y[i], strengths[i] = sp.subpixel_template(sx, sy, dx, dy, s_img, d_img,
                                                                     search_size=search_size, 
                                                                     template_size=template_size, **kwargs)

            # Capture the shifts
            shifts_x[i] = new_x[i] - dx
            shifts_y[i] = new_y[i] - dy

        self.matches.loc[mask, 'shift_x'] = shifts_x
        self.matches.loc[mask, 'shift_y'] = shifts_y
+1 −9
Original line number Diff line number Diff line
@@ -820,8 +820,7 @@ class CandidateGraph(nx.Graph):
            A networkX graph object

        """
        induced_nodes = nx.filters.show_nodes(self.nbunch_iter(nodes))
        return SubCandidateGraph(self, induced_nodes)
        return self.subgraph(nodes)

    def create_edge_subgraph(self, edges):
        """
@@ -1272,10 +1271,3 @@ class CandidateGraph(nx.Graph):
        """
        pass

class SubCandidateGraph(nx.graphviews.SubGraph, CandidateGraph):
    def __init__(self, *args, **kwargs):
        super(SubCandidateGraph, self).__init__(*args, **kwargs)


nx.graphviews.SubGraph = SubCandidateGraph
+4 −5
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import numpy as np
import pandas as pd
from plio.io.io_gdal import GeoDataset
from plio.io.isis_serial_number import generate_serial_number
from scipy.misc import bytescale, imresize
from skimage.transform import resize
from shapely.geometry import Polygon
from shapely import wkt

@@ -226,7 +226,7 @@ class Node(dict, MutableMapping):
        """

        array = self.geodata.read_array(band=band)
        return bytescale(array)
        return utils.bytescale(array)

    def get_array(self, band=1, **kwargs):
        """
@@ -353,8 +353,7 @@ class Node(dict, MutableMapping):
        pass

    def extract_features_with_downsampling(self, downsample_amount,
                                           array_read_args={},
                                           interp='lanczos', *args, **kwargs):
                                           array_read_args={}, *args, **kwargs):
        """
        Extract interest points for the this node (image) by first downsampling,
        then applying the extractor, and then upsampling the results backin to
@@ -369,7 +368,7 @@ class Node(dict, MutableMapping):
        total_size = array_size[0] * array_size[1]
        shape = (int(array_size[0] / downsample_amount),
                 int(array_size[1] / downsample_amount))
        array = imresize(self.geodata.read_array(**array_read_args), shape, interp=interp)
        array = resize(self.geodata.read_array(**array_read_args), shape, preserve_range=True)
        self.extract_features(array, *args, **kwargs)

        self.keypoints['x'] *= downsample_amount
Loading