class_docstr: Iterated patch-wise over the array, where the central patch is centred on the
  image centre.
  
  All yielded patches will be of size ``psize``. Areas outside of the array are
  filled with ``cval``. Besides the patch, a patch mask is returned, that denoted
  the outside values. Additionally, the n-dimensional grid id and a slicer object
  are returned.
  
  To extract the same patch from another array of the same size as ``array``, use
  the `applyslicer` method.
  
  The following schematic overview explains the behaviour to expect for even and odd
  images respectively patches. All ``O`` denote image voxels, ``|`` the patch
  borders and ``#`` padded voxels.
  
  One-dimensional image of size 5 with patch sizes 1, 2, 3, 4 and 5::
  
      |O|O|O|O|O|
  
      |#O|OO|OO|
  
      |##O|OOO|O##|
  
      |OOOO|O###|
  
      |OOOOO|
  
  One-dimensional image of size 4 with patch sizes 1, 2, 3 and 4::
  
      |O|O|O|O|
  
      |#O|OO|O#|
  
      |OOO|O##|
  
      |OOOO|
  
  
  Parameters
  ----------
  array : array_like
      A n-dimensional array.
  psize : int or sequence
      The patch size. If a single integer interpreted as hyper-cube.
  cval : number
      Value to fill undefined positions.
  
  Examples
  --------
  >>> import numpy
  >>> from medpy.iterators import CentredPatchIterator
  >>> arr = numpy.arange(0, 25).reshape((5,5))
  >>> arr
  array([[ 0,  1,  2,  3,  4],
         [ 5,  6,  7,  8,  9],
         [10, 11, 12, 13, 14],
         [15, 16, 17, 18, 19],
         [20, 21, 22, 23, 24]])
  >>> patches, pmasks, gridids, slicers = zip(*CentredPatchIterator(arr, 3))
  Total number of patches:
  >>> len(patches)
  9
  Central patch:
  >>> patches[4]
  array([[ 6,  7,  8],
         [11, 12, 13],
         [16, 17, 18]])
  Bottom-right corner patch:
  >>> patches[-1]
  array([[24,  0,  0],
         [ 0,  0,  0],
         [ 0,  0,  0]])
  And its definition mask:
  >>> pmasks[-1]
  array([[ True, False, False],
         [False, False, False],
         [False, False, False]], dtype=bool)
  One dimensional behaviour examples:
  >>> arr = range(1, 5)
  >>> len(arr)
  4
  >>> patches, pmasks, _, _ = zip(*CentredPatchIterator(arr, 1))
  >>> arr, patches
  ([1, 2, 3, 4], (array([1]), array([2]), array([3]), array([4])))
  >>> patches, _, _, _ = zip(*CentredPatchIterator(arr, 2))
  >>> arr, patches
  ([1, 2, 3, 4], (array([0, 1]), array([2, 3]), array([4, 0])))
  >>> patches, _, _, _ = zip(*CentredPatchIterator(arr, 3))
  >>> arr, patches
  ([1, 2, 3, 4], (array([1, 2, 3]), array([4, 0, 0])))
  >>> patches, _, _, _ = zip(*CentredPatchIterator(arr, 4))
  >>> arr, patches
  ([1, 2, 3, 4], (array([1, 2, 3, 4]),))
docstr: Assemble an image from a number of patches, patch masks and their grid ids.
  
  Parameters
  ----------
  patches : sequence
      Sequence of patches.
  pmasks : sequence
      Sequence of associated patch masks.
  gridids
      Sequence of associated grid ids.
  
  Returns
  -------
  image : ndarray
      The patches assembled back into an image of the original proportions.
  
  Examples
  --------
  Two-dimensional example:
  >>> import numpy
  >>> from medpy.iterators import CentredPatchIterator
  >>> arr = numpy.arange(0, 25).reshape((5,5))
  >>> arr
  array([[ 0,  1,  2,  3,  4],
         [ 5,  6,  7,  8,  9],
         [10, 11, 12, 13, 14],
         [15, 16, 17, 18, 19],
         [20, 21, 22, 23, 24]])
  >>> patches, pmasks, gridids, _ = zip(*CentredPatchIterator(arr, 2))
  >>> result = CentredPatchIterator.assembleimage(patches, pmasks, gridids)
  >>> numpy.all(arr == result)
  True
  
  Five-dimensional example:
  >>> arr = numpy.random.randint(0, 10, range(5, 10))
  >>> patches, pmasks, gridids, _ = zip(*CentredPatchIterator(arr, range(2, 7)))
  >>> result = CentredPatchIterator.assembleimage(patches, pmasks, gridids)
  >>> numpy.all(arr == result)
  True
docstr_tok: ["Assemble","an","image","from","a","number","of","patches",",","patch","masks","and","their","grid","ids",".","Parameters","--","--","--","--","--","patches",":","sequence","Sequence","of","patches",".","pmasks",":","sequence","Sequence","of","associated","patch","masks",".","gridids","Sequence","of","associated","grid","ids",".","Returns","--","--","--","-","image",":","ndarray","The","patches","assembled","back","into","an","image","of","the","original","proportions",".","Examples","--","--","--","--","Two-dimensional","example",":",">",">",">","import","numpy",">",">",">","from","medpy.iterators","import","CentredPatchIterator",">",">",">","arr","=","numpy.arange","(","0",",","25",")",".reshape","(","(","5,5",")",")",">",">",">","arr","array","(","[","[","0",",","1",",","2",",","3",",","4","]",",","[","5",",","6",",","7",",","8",",","9","]",",","[","10",",","11",",","12",",","13",",","14","]",",","[","15",",","16",",","17",",","18",",","19","]",",","[","20",",","21",",","22",",","23",",","24","]","]",")",">",">",">","patches",",","pmasks",",","gridids",",","_","=","zip","(","*","CentredPatchIterator","(","arr",",","2",")",")",">",">",">","result","=","CentredPatchIterator.assembleimage","(","patches",",","pmasks",",","gridids",")",">",">",">","numpy.all","(","arr","==","result",")","True","Five-dimensional","example",":",">",">",">","arr","=","numpy.random.randint","(","0",",","10",",","range","(","5",",","10",")",")",">",">",">","patches",",","pmasks",",","gridids",",","_","=","zip","(","*","CentredPatchIterator","(","arr",",","range","(","2",",","7",")",")",")",">",">",">","result","=","CentredPatchIterator.assembleimage","(","patches",",","pmasks",",","gridids",")",">",">",">","numpy.all","(","arr","==","result",")","True"]
code: def assembleimage(patches, pmasks, gridids):
      r"""
      Assemble an image from a number of patches, patch masks and their grid ids.
  
      Parameters
      ----------
      patches : sequence
          Sequence of patches.
      pmasks : sequence
          Sequence of associated patch masks.
      gridids
          Sequence of associated grid ids.
  
      Returns
      -------
      image : ndarray
          The patches assembled back into an image of the original proportions.
  
      Examples
      --------
      Two-dimensional example:
      >>> import numpy
      >>> from medpy.iterators import CentredPatchIterator
      >>> arr = numpy.arange(0, 25).reshape((5,5))
      >>> arr
      array([[ 0,  1,  2,  3,  4],
             [ 5,  6,  7,  8,  9],
             [10, 11, 12, 13, 14],
             [15, 16, 17, 18, 19],
             [20, 21, 22, 23, 24]])
      >>> patches, pmasks, gridids, _ = zip(*CentredPatchIterator(arr, 2))
      >>> result = CentredPatchIterator.assembleimage(patches, pmasks, gridids)
      >>> numpy.all(arr == result)
      True
  
      Five-dimensional example:
      >>> arr = numpy.random.randint(0, 10, range(5, 10))
      >>> patches, pmasks, gridids, _ = zip(*CentredPatchIterator(arr, range(2, 7)))
      >>> result = CentredPatchIterator.assembleimage(patches, pmasks, gridids)
      >>> numpy.all(arr == result)
      True
      """
      for d in range(patches[0].ndim):
          groups = {}
          for patch, pmask, gridid in zip(patches, pmasks, gridids):
              groupid = gridid[1:]
              if not groupid in groups:
                  groups[groupid] = []
              groups[groupid].append((patch, pmask, gridid[0]))
          patches = []
          gridids = []
          pmasks = []
          for groupid, group in list(groups.items()):
              patches.append(
                  numpy.concatenate(
                      [
                          p
                          for p, _, _ in sorted(
                              group, key=itemgetter(2)
                          )
                      ],
                      d,
                  )
              )
              pmasks.append(
                  numpy.concatenate(
                      [
                          m
                          for _, m, _ in sorted(
                              group, key=itemgetter(2)
                          )
                      ],
                      d,
                  )
              )
              gridids.append(groupid)
      objs = find_objects(pmasks[0])
      if not 1 == len(objs):
          raise ValueError(
              "The assembled patch masks contain more than one binary object."
          )
      return patches[0][objs[0]]
  
imports: from itertools import product
  import numpy
  from operator import itemgetter
  from scipy.ndimage import find_objects
label_desc: Use image node_id 5 for calling the CentredPatchIterator obj's underlying member method code with example usage: obj.assembleimage(patches, pmasks, gridids) and returns: patches