code: def images2neibs(ten4, neib_shape, neib_step=None, mode="valid"):
      """
      Function :func:`images2neibs <theano.tensor.nnet.neighbours.images2neibs>`
      allows to apply a sliding window operation to a tensor containing
      images or other two-dimensional objects.
      The sliding window operation loops over points in input data and stores
      a rectangular neighbourhood of each point.
      It is possible to assign a step of selecting patches (parameter `neib_step`).
  
      Parameters
      ----------
      ten4 : A 4d tensor-like
          A 4-dimensional tensor which represents a list of lists of images.
          It should have shape (list 1 dim, list 2 dim, row, col). The first
          two dimensions can be useful to store different channels and batches.
      neib_shape : A 1d tensor-like of 2 values
          A tuple containing two values: height and width of the neighbourhood.
          It should have shape (r,c) where r is the height of the neighborhood
          in rows and c is the width of the neighborhood in columns.
      neib_step : A 1d tensor-like of 2 values
          (dr,dc) where dr is the number of rows to skip between patch and dc is
          the number of columns. The parameter should be a tuple of two elements:
          number of rows and number of columns to skip each iteration.
          Basically, when the step is 1, the neighbourhood of every first element
          is taken and every possible rectangular subset is returned.
          By default it is equal to `neib_shape` in other words, the patches are
          disjoint. When the step is greater than `neib_shape`, some elements are
          omitted. When None, this is the same as neib_shape (patch are disjoint).
      mode : {'valid', 'ignore_borders', 'wrap_centered', 'half'}
          ``valid``
              Requires an input that is a multiple of the
              pooling factor (in each direction).
          ``half``
              Equivalent to 'valid' if we pre-pad with zeros the input on
              each side by (neib_shape[0]//2, neib_shape[1]//2)
          ``full``
              Equivalent to 'valid' if we pre-pad with zeros the input on
              each side by (neib_shape[0] - 1, neib_shape[1] - 1)
          ``ignore_borders``
              Same as valid, but will ignore the borders if the shape(s) of
              the input is not a multiple of the pooling factor(s).
          ``wrap_centered``
              ?? TODO comment
  
      Returns
      -------
      object
          Reshapes the input as a 2D tensor where each row is an
          pooling example. Pseudo-code of the output:
  
            .. code-block:: python
  
               idx = 0
               for i in xrange(list 1 dim):
                   for j in xrange(list 2 dim):
                       for k in <image column coordinates>:
                           for l in <image row coordinates>:
                               output[idx,:]
                                    = flattened version of ten4[i,j,l:l+r,k:k+c]
                               idx += 1
  
            .. note:: The operation isn't necessarily implemented internally with
               these for loops, they're just the easiest way to describe the
               output pattern.
  
      Notes
      -----
      .. note::
          Currently the step size should be chosen in the way that the
          corresponding dimension :math:`i` (width or height) is equal
          to :math:`n * step\_size_i + neib\_shape_i` for some :math:`n`.
  
      Examples
      --------
  
      .. code-block:: python
  
          # Defining variables
          images = T.tensor4('images')
          neibs = images2neibs(images, neib_shape=(5, 5))
  
          # Constructing theano function
          window_function = theano.function([images], neibs)
  
          # Input tensor (one image 10x10)
          im_val = np.arange(100.).reshape((1, 1, 10, 10))
  
          # Function application
          neibs_val = window_function(im_val)
  
      .. note:: The underlying code will construct a 2D tensor of disjoint
         patches 5x5. The output has shape 4x25.
  
      """
      return Images2Neibs(mode)(ten4, neib_shape, neib_step)
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import theano
  from theano import Op, Apply
  from theano.gof import EnumList
  import theano.tensor
  from theano.gradient import grad_not_implemented
  from theano.gradient import grad_undefined
label_desc: Use image node_id 1 for calling a global function with example usage: images2neibs(ten4, neib_shape, neib_step, mode) and returns: Images2Neibs