Commit a60d1416 authored by jay's avatar jay
Browse files

Adds subpixel matcher and bumps tests

parent 3f8d0bc3
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -90,15 +90,6 @@ def subpixel_phase(template, search, **kwargs):
    (y_shift, x_shift), error, diffphase = register_translation(search, template, **kwargs)
    return x_shift, y_shift, (error, diffphase)

def subpixel_composite(asub, bsub, b_subpixel_shift=[0,0], template_extents=25, phase_kwargs={}, template_kwargs={}):
    x_shift, y_shift, error = subpixel_phase(asub, bsub, **phase_kwargs)

    asize = asub.shape
    bsize = bsub.shape

    amini = asub[asub.shape]


def subpixel_offset(template, search, **kwargs):
    """
    Uses a pattern-matcher on subsets of two images determined from the passed-in keypoints and optional sizes to
+34 −12
Original line number Diff line number Diff line
@@ -2,27 +2,49 @@ import os
import sys
import unittest

import numpy as np

from .. import subpixel as sp
import pytest

sys.path.append(os.path.abspath('..'))
import numpy as np
from scipy.ndimage import imread

from autocnet.examples import get_path
import autocnet.matcher.subpixel as sp

class TestSubPixel(unittest.TestCase):

    def setup(self):
        pass
@pytest.fixture
def apollo_subsets():
    arr1 = imread(get_path('AS15-M-0295_SML(1).png'))[100:200, 123:223]
    arr2 = imread(get_path('AS15-M-0295_SML(2).png'))[235:335, 95:195]
    print(arr1.shape, arr2.shape)
    return arr1, arr2

    def test_clip_roi(self):
def test_clip_roi():
    img = np.arange(10000).reshape(100, 100)
    center = (4, 4)

    clip = sp.clip_roi(img, center, 9)
        self.assertEqual(clip.mean(), 404)
    assert clip.mean() == 404

    center = (55.4, 63.1)
    clip = sp.clip_roi(img, center, 27)
        self.assertEqual(clip.mean(), 6355.0)

        self.assertRaises(ValueError, sp.clip_roi, img, center, 10)
    assert clip.mean() == 6355.0

def test_subpixel_phase(apollo_subsets):
    a = apollo_subsets[0]
    b = apollo_subsets[1]

    xoff, yoff, err = sp.subpixel_phase(a, b)
    assert xoff == 0
    assert yoff == 2
    assert len(err) == 2

def test_subpixel_template(apollo_subsets):
    a = apollo_subsets[0]
    b = apollo_subsets[1]
    midy = int(b.shape[0] / 2)
    midx = int(b.shape[1] / 2)
    subb = b[midy-10:midy+10, midx-10:midx+10]
    xoff, yoff, err = sp.subpixel_offset(subb, a)
    assert xoff == 0.0625 
    assert yoff == 2.125 
    assert err == 0.9905822277069092