Exemplo n.º 1
0
 def test_zoom(self):
     _T, _Z, _R = translate(), zoom(1.2, 0.7), rotate()
     A = _T @ _Z @ _R  # TZR
     T, Z, R = decompose_affine2d(A)
     for expect, out in zip([_T, _Z, _R], [T, Z, R]):
         with self.subTest(out=out, expect=expect):
             self.assertTrue(np.isclose(expect, out).all())
Exemplo n.º 2
0
    def test_transforms_graphical(self):
        im = PewImage(self.img)
        A1, A2, A3 = zoom(1, 1.5), shear(0.3, 0), rotate(45)
        _im1 = im.affine_transform(A1)
        _im2 = im.affine_transform(A2)
        _im3 = im.affine_transform(A3)

        centre = np.array(im.image.size) / 2.0
        fig, ax = plt.subplots(2, 4, figsize=(12, 3), sharex=True, sharey=True)
        ax[0, 0].scatter(*centre, color="r")
        # get the max extent of images
        x0, x1, y0, y1 = 0, 1, 0, 1
        for ix, I in enumerate([im, _im1, _im2, _im3]):
            x0, x1, y0, y1 = (
                min(x0, np.min(I.extent[:2])),
                max(x1, np.max(I.extent[:2])),
                min(y0, np.min(I.extent[2:])),
                max(y1, np.max(I.extent[2:])),
            )
            ax[0, ix].imshow(I.image)
            ax[1, ix].imshow(I.image, extent=I.extent)

        size = np.max(im.image.size) * np.sqrt(2)
        ax = ax.flat

        for a in ax:
            a.set_aspect("equal")
            a.axis([x0, x1, y0, y1])
Exemplo n.º 3
0
    def test_default(self):

        fig, ax = plt.subplots(2, 4, sharey=True, sharex=True, figsize=(10, 4))
        ax = ax.flat
        for ix, A in enumerate([
                translate(0.5, 1.0),
                zoom(1.0, 0.5),
                rotate(30),
                shear(0.5, 0),
                translate(0.5, 0),
                zoom(2, 1),
                rotate(-30),
                shear(0, 0.5),
        ]):
            vis(A, ax=ax[ix])

        plt.tight_layout()
Exemplo n.º 4
0
 def test_reconstruction(self):
     _T, _Z, _R = translate(40, 50), zoom(1.5, 0.5), rotate(-15)
     A = _T @ _Z @ _R  # TZR
     _A = compose_affine2d(*decompose_affine2d(A))
     self.assertTrue(np.isclose(A, _A).all())
Exemplo n.º 5
0
 def test_affine_transform(self):
     im = PewImage(self.img)
     affine_im = im.affine_transform(rotate(30))