def warp_to_shape(self, template_shape, transform, warp_landmarks=True,
                      order=1, mode='constant', cval=0.0, batch_size=None,
                      return_transform=False):
        """
        Return a copy of this image warped into a different reference space.

        Parameters
        ----------
        template_shape : `tuple` or `ndarray`
            Defines the shape of the result, and what pixel indices should be
            sampled (all of them).
        transform : :map:`Transform`
            Transform **from the template_shape space back to this image**.
            Defines, for each index on template_shape, which pixel location
            should be sampled from on this image.
        warp_landmarks : `bool`, optional
            If ``True``, result will have the same landmark dictionary
            as self, but with each landmark updated to the warped position.
        order : `int`, optional
            The order of interpolation. The order has to be in the range [0,5]
            
            ========= ====================
            Order     Interpolation
            ========= ====================
            0         Nearest-neighbor
            1         Bi-linear *(default)*
            2         Bi-quadratic
            3         Bi-cubic
            4         Bi-quartic
            5         Bi-quintic
            ========= ====================

        mode : ``{constant, nearest, reflect, wrap}``, optional
            Points outside the boundaries of the input are filled according
            to the given mode.
        cval : `float`, optional
            Used in conjunction with mode ``constant``, the value outside
            the image boundaries.
        batch_size : `int` or ``None``, optional
            This should only be considered for large images. Setting this
            value can cause warping to become much slower, particular for
            cached warps such as Piecewise Affine. This size indicates
            how many points in the image should be warped at a time, which
            keeps memory usage low. If ``None``, no batching is used and all
            points are warped at once.
        return_transform : `bool`, optional
            This argument is for internal use only. If ``True``, then the
            :map:`Transform` object is also returned.

        Returns
        -------
        warped_image : `type(self)`
            A copy of this image, warped.
        transform : :map:`Transform`
            The transform that was used. It only applies if
            `return_transform` is ``True``.
        """
        template_shape = np.array(template_shape, dtype=np.int)
        if (isinstance(transform, Affine) and order in range(4) and
            self.n_dims == 2):

            # we are going to be able to go fast.

            if isinstance(transform, Translation) and order == 0:
                # an integer translation (e.g. a crop) If this lies entirely
                # in the bounds then we can just do a copy. We need to match
                # the behavior of cython_interpolation exactly, which means
                # matching its rounding behavior too:
                t = transform.translation_component.copy()
                pos_t = t > 0.0
                t[pos_t] += 0.5
                t[~pos_t] -= 0.5
                min_ = t.astype(np.int)
                max_ = template_shape + min_
                if np.all(np.array(self.shape) <= max_) and np.all(min_ >= 0):
                    # we have a crop - slice the pixels.
                    warped_pixels = self.pixels[:,
                                    int(min_[0]):int(max_[0]),
                                    int(min_[1]):int(max_[1])].copy()
                    return self._build_warp_to_shape(warped_pixels, transform,
                                                     warp_landmarks,
                                                     return_transform)
            # we couldn't do the crop, but skimage has an optimised Cython
            # interpolation for 2D affine warps - let's use that
            sampled = cython_interpolation(self.pixels, template_shape,
                                           transform, order=order,
                                           mode=mode, cval=cval)
        else:
            template_points = indices_for_image_of_shape(template_shape)
            points_to_sample = transform.apply(template_points,
                                               batch_size=batch_size)
            sampled = self.sample(points_to_sample,
                                  order=order, mode=mode, cval=cval)

        # set any nan values to 0
        sampled[np.isnan(sampled)] = 0
        # build a warped version of the image
        warped_pixels = sampled.reshape(
            (self.n_channels,) + tuple(template_shape))

        return self._build_warp_to_shape(warped_pixels, transform,
                                         warp_landmarks, return_transform)
dataset/ETHPy150Open menpo/menpo/menpo/image/base.py/Image.warp_to_shape/swapped operands of `<=`