コード例 #1
0
def patch_match(a, b, angles=360, Rs=None, plot_corr=False):
    """Align two patches, using the log polar transform.

    Parameters
    ----------
    a : ndarray of uint8
        Reference image.
    b : ndarray of uint8
        Target image.
    angles : int
        Number of angles to use in log-polar transform.
    Rs : int
        Number of radial samples used in the log-polar transform.
    plot_corr : bool, optional
        Whether to plot the phase correlation coefficients.

    Returns
    -------
    c : float
        Peak correlation value.
    theta : float
        Estimated rotation angle from `a` to `b`.
    scale : float
        Estimated scaling from `a` to `b`.

    """
    from image import phase_corr
    import supreme.transform as tr

    angles = np.linspace(0, np.pi * 2, angles)
    if Rs is None:
        Rs = max(a.shape[:2])
    A, angles, log_base = tr.logpolar(a, angles=angles, Rs=Rs, extra_info=True)
    B = tr.logpolar(b, angles=angles, Rs=Rs)

    cv = phase_corr(B, A)
    m, n = np.unravel_index(np.argmax(cv), cv.shape)

    if n > Rs/2:
        n = n - Rs # correlation matched, but from the other side

    if plot_corr:
        import matplotlib.pyplot as plt
        from mpl_toolkits.mplot3d import axes3d

        fig = plt.figure()

        cv_cut = cv[max(0, m - 30):min(cv.shape[1], m + 30),
                    max(0, n - 30):min(cv.shape[0], n + 30)]

        coords = sr.geometry.Grid(*cv_cut.shape)

        ax3d = axes3d.Axes3D(fig)
        ax3d.plot_wireframe(coords['cols'], coords['rows'], cv_cut)
        ax3d.set_title('Phase correlation around peak\n$\\log(100 + x)$')
        plt.show()

    return cv[m, n], angles[m], np.exp(n * log_base)
コード例 #2
0
    def test_logpolar(self, level=1):
        x = np.zeros((3, 3))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3))

        x = np.zeros((3, 3, 3))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3, 3))

        x = np.zeros((3, 3, 4))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3, 4))
        z = transform.logpolar(x, angles=np.linspace(0, 2 * np.pi, 400))
        assert_equal(z.shape, (400, 3, 4))
コード例 #3
0
ファイル: test_transform.py プロジェクト: Germanc/supreme
    def test_logpolar(self, level=1):
        x = np.zeros((3, 3))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3))

        x = np.zeros((3, 3, 3))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3, 3))

        x = np.zeros((3, 3, 4))
        z = transform.logpolar(x)
        assert_equal(z.shape, (12, 3, 4))
        z = transform.logpolar(x, angles=np.linspace(0, 2*np.pi, 400))
        assert_equal(z.shape, (400, 3, 4))
コード例 #4
0
 def test_logpolar_on_zeros(self):
     x = np.zeros((3))
     transform.logpolar(x)
コード例 #5
0
ファイル: test_transform.py プロジェクト: Germanc/supreme
 def test_logpolar_on_zeros(self):
     x = np.zeros((3))
     transform.logpolar(x)