Esempio n. 1
0
def test_split_translation():
    def verify(a, b):
        a = np.asarray(a)
        b = np.asarray(b)
        np.testing.assert_array_almost_equal(a, b)

    def tt(tx, ty, *expect):
        verify(split_translation((tx, ty)), expect)

    assert split_translation((1, 2)) == ((1, 2), (0, 0))
    assert split_translation((-1, -2)) == ((-1, -2), (0, 0))
    tt(1.3, 2.5, (1, 2), (0.3, 0.5))
    tt(1.1, 2.6, (1, 3), (0.1, -0.4))
    tt(-1.1, 2.8, (-1, 3), (-0.1, -0.2))
    tt(-1.9, 2.05, (-2, 2), (+0.1, 0.05))
    tt(-1.5, 2.45, (-1, 2), (-0.5, 0.45))
Esempio n. 2
0
def _norm_grid(A: Affine, tol=1e-8) -> Union[F4, F6]:
    """Compute normalised grid.

    Different grids related via whole pixel translation will have the same
    normalised grid.

    Scale and Translation only
    --------------------------

    Normalised grid is defined by:

       sx, sy, tx, ty

    Where sx, sy is resolution (CRS units per pixel)
    and (tx, ty) is sub-pixel translation in (-0.5, 0.5)

    Order is: subpix translate -> scale

    General Case
    ------------

    Normalised grid is defined by:

       sx, sy, tx, ty, ca, w

    Order is: subpix translate -> scale -> rotate+shear

    WARNING: general case is not currently implemented
    """

    R, W, S = decompose_rws(A)

    (ca, _, tx, _, _, ty, *_) = R

    (_, w, *_) = W

    (sx, _, _, _, sy, *_) = S

    is_st = abs(ca - 1) < tol and abs(w) < tol

    if is_st:
        # No rotation no shear -- commonest case
        # sx, sy, tx, ty fully defines the grid

        # Tw*S*Xp == S*Tp*Xp
        #
        # Here `p` is Pixel, `w` is World

        # convert from: <Scale pixels to World, then translate>
        # into        : <Translate pixels then scale to World>
        tx_p, ty_p = tx / sx, ty / sy

        # Remove whole pixel translation to normalise grid
        _, (tx_p, ty_p) = split_translation((tx_p, ty_p))

        return (maybe_int(sx, tol), maybe_int(sy, tol), maybe_zero(tx_p, tol),
                maybe_zero(ty_p, tol))
    else:
        raise NotImplementedError('TODO: rotated grids')
Esempio n. 3
0
 def tt(tx, ty, *expect):
     verify(split_translation((tx, ty)), expect)