code: def timeseries_to_matrix( image, mask=None ):
      
      temp = utils.ndimage_to_list( image )
      if mask is None:
          mask = temp[0]*0 + 1
      return image_list_to_matrix( temp, mask )
docs: Convert a timeseries image into a matrix.
  
      ANTsR function: `timeseries2matrix`
  
      Arguments
      ---------
      image : image whose slices we convert to a matrix. E.g. a 3D image of size
             x by y by z will convert to a z by x*y sized matrix
  
      mask : ANTsImage (optional)
          image containing binary mask. voxels in the mask are placed in the matrix
  
      Returns
      -------
      ndarray
          array with a row for each image
          shape = (N_IMAGES, N_VOXELS)
  
      Example
      -------
      >>> import ants
      >>> img = ants.make_image( (10,10,10,5 ) )
      >>> mat = ants.timeseries_to_matrix( img )