menpo/image/base.py
def extract_patches(self, patch_centers, patch_size=(16, 16),
                        sample_offsets=None, as_single_array=False):
        r"""
        Extract a set of patches from an image. Given a set of patch centers and
        a patch size, patches are extracted from within the image, centred
        on the given coordinates. Sample offsets denote a set of offsets to
        extract from within a patch. This is very useful if you want to extract
        a dense set of features around a set of landmarks and simply sample the
        same grid of patches around the landmarks.

        If sample offsets are used, to access the offsets for each patch you
        need to slice the resulting list. So for 2 offsets, the first centers
        offset patches would be ``patches[:2]``.

        Currently only 2D images are supported.

        Parameters
        ----------
        patch_centers : :map:`PointCloud`
            The centers to extract patches around.
        patch_size : `tuple` or `ndarray`, optional
            The size of the patch to extract
        sample_offsets : :map:`PointCloud`, optional
            The offsets to sample from within a patch. So (0, 0) is the centre
            of the patch (no offset) and (1, 0) would be sampling the patch
            from 1 pixel up the first axis away from the centre.
        as_single_array : `bool`, optional
            If ``True``, an ``(n_center * n_offset, self.shape...)``
            `ndarray`, thus a single numpy array is returned containing each
            patch. If ``False``, a `list` of :map:`Image` objects is returned
            representing each patch.

        Returns
        -------
        patches : `list` or `ndarray`
            Returns the extracted patches. Returns a list if
            ``as_single_array=True`` and an `ndarray` if
            ``as_single_array=False``.

        Raises
        ------
        ValueError
            If image is not 2D
        """
        if self.n_dims != 2:
            raise ValueError('Only two dimensional patch extraction is '
                             'currently supported.')

        if sample_offsets is None:
            sample_offsets_arr = np.zeros([1, 2], dtype=np.int64)
        else:
            sample_offsets_arr = np.require(sample_offsets.points,
                                            dtype=np.int64)

        single_array = extract_patches_cython(self.pixels,
                                              patch_centers.points,
                                              np.asarray(patch_size,
                                                         dtype=np.int64),
                                              sample_offsets_arr)

        if as_single_array:
            return single_array
        else:
            return [Image(p, copy=False) for p in single_array]
r"""
        Extract a set of patches from an image. Given a set of patch centers and
        a patch size, patches are extracted from within the image, centred
        on the given coordinates. Sample offsets denote a set of offsets to
        extract from within a patch. This is very useful if you want to extract
        a dense set of features around a set of landmarks and simply sample the
        same grid of patches around the landmarks.

        If sample offsets are used, to access the offsets for each patch you
        need to slice the resulting list. So for 2 offsets, the first centers
        offset patches would be ``patches[:2]``.

        Currently only 2D images are supported.

        Parameters
        ----------
        patch_centers : :map:`PointCloud`
            The centers to extract patches around.
        patch_size : `tuple` or `ndarray`, optional
            The size of the patch to extract
        sample_offsets : :map:`PointCloud`, optional
            The offsets to sample from within a patch. So (0, 0) is the centre
            of the patch (no offset) and (1, 0) would be sampling the patch
            from 1 pixel up the first axis away from the centre.
        as_single_array : `bool`, optional
            If ``True``, an ``(n_center * n_offset, self.shape...)``
            `ndarray`, thus a single numpy array is returned containing each
            patch. If ``False``, a `list` of :map:`Image` objects is returned
            representing each patch.

        Returns
        -------
        patches : `list` or `ndarray`
            Returns the extracted patches. Returns a list if
            ``as_single_array=True`` and an `ndarray` if
            ``as_single_array=False``.

        Raises
        ------
        ValueError
            If image is not 2D
        
r"""
Extract a set of patches from an image. Given a set of patch centers and
a patch size, patches are extracted from within the image, centred
on the given coordinates. Sample offsets denote a set of offsets to
extract from within a patch. This is very useful if you want to extract
a dense set of features around a set of landmarks and simply sample the
same grid of patches around the landmarks.

If sample offsets are used, to access the offsets for each patch you
need to slice the resulting list. So for 2 offsets, the first centers
offset patches would be ``patches[:2]``.

Currently only 2D images are supported.

Parameters

patch_centers : :map:`PointCloud`
The centers to extract patches around.

Returns

patches : `list` or `ndarray`
Returns the extracted patches.

Raises

ValueError
If image is not 2D
r " " " Extract a set of patches from an image . Given a set of patch centers and a patch size patches are extracted from within the image centred on the given coordinates . Sample offsets denote a set of offsets to extract from within a patch . This is very useful if you want to extract a dense set of features around a set of landmarks and simply sample the same grid of patches around the landmarks . If sample offsets are used to access the offsets for each patch you need to slice the resulting list . So for 2 offsets the first centers offset patches would be ` ` patches [ : 2 ] ` ` . Currently only 2D images are supported . Parameters patch_centers : : map : ` PointCloud ` The centers to extract patches around . Returns patches : ` list ` or ` ndarray ` Returns the extracted patches . Raises ValueError If image is not 2D
def extract_patches(self, patch_centers, patch_size=(16, 16),
                        sample_offsets=None, as_single_array=False):
        if self.n_dims != 2:
            raise ValueError('Only two dimensional patch extraction is '
                             'currently supported.')
        if sample_offsets is None:
            sample_offsets_arr = np.zeros([1, 2], dtype=np.int64)
        else:
            sample_offsets_arr = np.require(sample_offsets.points,
                                            dtype=np.int64)
        single_array = extract_patches_cython(self.pixels,
                                              patch_centers.points,
                                              np.asarray(patch_size,
                                                         dtype=np.int64),
                                              sample_offsets_arr)
        if as_single_array:
            return single_array
        else:
            return [Image(p, copy=False) for p in single_array]
def extract_patches ( self , patch_centers , patch_size = ( 16 , 16 ) , sample_offsets = None , as_single_array = False ) : if self . n_dims != 2 : raise ValueError ( 'Only two dimensional patch extraction is ' 'currently supported.' ) if sample_offsets is None : sample_offsets_arr = np . zeros ( [ 1 , 2 ] , dtype = np . int64 ) else : sample_offsets_arr = np . require ( sample_offsets . points , dtype = np . int64 ) single_array = extract_patches_cython ( self . pixels , patch_centers . points , np . asarray ( patch_size , dtype = np . int64 ) , sample_offsets_arr ) if as_single_array : return single_array else : return [ Image ( p , copy = False ) for p in single_array ]
r"""
Extract a set of patches from an image.
r " " " Extract a set of patches from an image .
r"""
        Extract a set of patches from an image. Given a set of patch centers and
        a patch size, patches are extracted from within the image, centred
        on the given coordinates. Sample offsets denote a set of offsets to
        extract from within a patch. This is very useful if you want to extract
        a dense set of features around a set of landmarks and simply sample the
        same grid of patches around the landmarks.

        If sample offsets are used, to access the offsets for each patch you
        need to slice the resulting list. So for 2 offsets, the first centers
        offset patches would be ``patches[:2]``.

        Currently only 2D images are supported.

        Parameters
        ----------
        patch_centers : :map:`PointCloud`
            The centers to extract patches around.
        patch_size : `tuple` or `ndarray`, optional
            The size of the patch to extract
        sample_offsets : :map:`PointCloud`, optional
            The offsets to sample from within a patch. So (0, 0) is the centre
            of the patch (no offset) and (1, 0) would be sampling the patch
            from 1 pixel up the first axis away from the centre.
        as_single_array : `bool`, optional
            If ``True``, an ``(n_center * n_offset, self.shape...)``
            `ndarray`, thus a single numpy array is returned containing each
            patch. If ``False``, a `list` of :map:`Image` objects is returned
            representing each patch.

        Returns
        -------
        patches : `list` or `ndarray`
            Returns the extracted patches. Returns a list if
            ``as_single_array=True`` and an `ndarray` if
            ``as_single_array=False``.

        Raises
        ------
        ValueError
            If image is not 2D
        """
self
patch_centers
patch_size
sample_offsets
as_single_array