#NEWLINE# def set_patches( self , patches , patch_centers , offset = None , offset_index = None ) : #NEWLINE# #INDENT# "\n        Set the values of a group of patches into the correct regions of\n        **this** image. Given an array of patches and a set of patch centers,\n        the patches' values are copied in the regions of the image that are\n        centred on the coordinates of the given centers.\n\n        The patches argument can have any of the two formats that are returned\n        from the `extract_patches()` and `extract_patches_around_landmarks()`\n        methods. Specifically it can be:\n\n            1. ``(n_center, n_offset, self.n_channels, patch_shape)`` `ndarray`\n            2. `list` of ``n_center * n_offset`` :map:`Image` objects\n\n        Currently only 2D images are supported.\n\n        Parameters\n        ----------\n        patches : `ndarray` or `list`\n            The values of the patches. It can have any of the two formats that\n            are returned from the `extract_patches()` and\n            `extract_patches_around_landmarks()` methods. Specifically, it can\n            either be an ``(n_center, n_offset, self.n_channels, patch_shape)``\n            `ndarray` or a `list` of ``n_center * n_offset`` :map:`Image`\n            objects.\n        patch_centers : :map:`PointCloud`\n            The centers to set the patches around.\n        offset : `list` or `tuple` or ``(1, 2)`` `ndarray` or ``None``, optional\n            The offset to apply on the patch centers within the image.\n            If ``None``, then ``(0, 0)`` is used.\n        offset_index : `int` or ``None``, optional\n            The offset index within the provided `patches` argument, thus the\n            index of the second dimension from which to sample. If ``None``,\n            then ``0`` is used.\n\n        Raises\n        ------\n        ValueError\n            If image is not 2D\n        ValueError\n            If offset does not have shape (1, 2)\n        " #NEWLINE# if ( self . n_dims != 2 ) : #NEWLINE# #INDENT# raise ValueError ( 'Only two dimensional patch insertion is currently supported.' ) #NEWLINE# #UNINDENT# if ( offset is None ) : #NEWLINE# #INDENT# offset = np . zeros ( [ 1 , 2 ] , dtype = np . intp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( offset , tuple ) or isinstance ( offset , list ) ) : #NEWLINE# #INDENT# offset = np . asarray ( [ offset ] ) #NEWLINE# #UNINDENT# #UNINDENT# offset = np . require ( offset , dtype = np . intp ) #NEWLINE# if ( not ( offset . shape == ( 1 , 2 ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'The offset must be a tuple, a list or a numpy.array with shape (1, 2).' ) #NEWLINE# #UNINDENT# if ( offset_index is None ) : #NEWLINE# #INDENT# offset_index = 0 #NEWLINE# #UNINDENT# if isinstance ( patches , list ) : #NEWLINE# #INDENT# patches = _convert_patches_list_to_single_array ( patches , patch_centers . n_points ) #NEWLINE# #UNINDENT# tmp_pixels = self . pixels . astype ( np . uint8 ) #NEWLINE# set_patches ( patches . astype ( np . uint8 ) , tmp_pixels , patch_centers . points , offset , offset_index ) #NEWLINE# self . pixels = tmp_pixels . astype ( np . bool )