Example #1
0
    def shapes(self, as_points=False):
        r"""
        Generates a list containing the shapes obtained at each fitting
        iteration.

        Parameters
        -----------
        as_points: boolean, optional
            Whether the results is returned as a list of PointClouds or
            ndarrays.

            Default: False

        Returns
        -------
        shapes: :class:`menpo.shape.PointCoulds or ndarray list
            A list containing the shapes obtained at each fitting iteration.
        """
        downscale = self.fitter._downscale
        n = self.n_levels - 1

        shapes = []
        for j, f in enumerate(self.basic_fittings):
            if downscale and not self.scaled_levels:
                transform = Scale(downscale**(n-j), 2)
                for t in f.shapes(as_points=as_points):
                    transform.apply_inplace(t)
                    shapes.append(self.affine_correction.apply(t))
            else:
                for t in f.shapes(as_points=as_points):
                    shapes.append(self.affine_correction.apply(t))

        return shapes
Example #2
0
    def tcoords_pixel_scaled(self):
        r"""
        Returns a PointCloud that is modified to be suitable for directly
        indexing into the pixels of the texture (e.g. for manual mapping
        operations). The resulting tcoords behave just like image landmarks
        do:

         >>> texture = texturedtrimesh.texture
         >>> tc_ps = texturedtrimesh.tcoords_pixel_scaled()
         >>> pixel_values_at_tcs = texture[tc_ps[: ,0], tc_ps[:, 1]]

        The operations that are performed are:

        - Flipping the origin from bottom-left to top-left
        - Scaling the tcoords by the image shape (denormalising them)
        - Permuting the axis so that

        Returns
        -------
        tcoords_scaled : :class:`menpo.shape.PointCloud`
            A copy of the tcoords that behave like Image landmarks
        """
        scale = Scale(np.array(self.texture.shape)[::-1])
        tcoords = self.tcoords.points.copy()
        # flip the 'y' st 1 -> 0 and 0 -> 1, moving the axis to upper left
        tcoords[:, 1] = 1 - tcoords[:, 1]
        # apply the scale to get the units correct
        tcoords = scale.apply(tcoords)
        # flip axis 0 and axis 1 so indexing is as expected
        tcoords = tcoords[:, ::-1]
        return PointCloud(tcoords)
Example #3
0
def scale_compose_after_inplace_homog_test():
    # can't do this inplace - so should just give transform chain
    homog = HomogeneousTransform(np.array([[0, 1, 0],
                                           [1, 0, 0],
                                           [0, 0, 1]]))
    s = Scale([3, 4])
    s.compose_after_inplace(homog)
Example #4
0
def scale_compose_after_homog_test():
    # can't do this inplace - so should just give transform chain
    homog = HomogeneousTransform(np.array([[0, 1, 0],
                                           [1, 0, 0],
                                           [0, 0, 1]]))
    s = Scale([3, 4])
    res = s.compose_after(homog)
    assert(isinstance(res, TransformChain))
Example #5
0
def chain_compose_before_tps_test():
    a = PointCloud(np.random.random([10, 2]))
    b = PointCloud(np.random.random([10, 2]))
    tps = TPS(a, b)

    t = Translation([3, 4])
    s = Scale([4, 2])
    chain = TransformChain([t, s])
    chain_mod = chain.compose_before(tps)

    points = PointCloud(np.random.random([10, 2]))

    manual_res = tps.apply(s.apply(t.apply(points)))
    chain_res = chain_mod.apply(points)
    assert(np.all(manual_res.points == chain_res.points))