parameters: (vol_size, patch_size, patch_stride=1, start_sub=0, nargout=1)
docstring: Number of patches that fit into volSize given a particular patch_size. patch_strideb
      cropped to the maximum size that fits the patch grid. For example, a [6x6] volume with
      patch_size opatch_stridee
  
      Parameters:
          vol_size (numpy vector): the size of the input volume
          patch_size (numpy vector): the size of the patches
          patch_stride (int or numpy vector, optional): stride (separation) in each dimension.
              default: 1
          start_sub (int or numpy vector, optional): the volume location where patches start
              This essentially means that the volume will be cropped starting at that location.
              e.g. if startSub is [2, 2], then only vol(2:end, 2:end) will be included.
              default: 0
          nargout (int, 1 or 2): optionally output new (cropped) volume size.
              return the grid_size only if nargout is 1, or (grid_size, new_vol_size)
              if narout is 2.
      Returns:
          grid_size only, if nargout is 1, or
          (grid_size, new_vol_size) if narout is 2
  
      See Also:
          grid()
  
      Contact:
          {adalca,klbouman}@csail.mit.edu
docstring_summary: Number of patches that fit into volSize given a particular patch_size. patch_strideb
      cropped to the maximum size that fits the patch grid. For example, a [6x6] volume with
      patch_size opatch_stridee
docstring_tokens: Number of patches that fit into volSize given a particular patch_size . patch_strideb cropped to the maximum size that fits the patch grid . For example a [ 6x6 ] volume with patch_size opatch_stridee
function: def gridsize(vol_size, patch_size, patch_stride=1, start_sub=0, nargout=1):
      """
      Number of patches that fit into volSize given a particular patch_size. patch_strideb
      cropped to the maximum size that fits the patch grid. For example, a [6x6] volume with
      patch_size opatch_stridee
  
      Parameters:
          vol_size (numpy vector): the size of the input volume
          patch_size (numpy vector): the size of the patches
          patch_stride (int or numpy vector, optional): stride (separation) in each dimension.
              default: 1
          start_sub (int or numpy vector, optional): the volume location where patches start
              This essentially means that the volume will be cropped starting at that location.
              e.g. if startSub is [2, 2], then only vol(2:end, 2:end) will be included.
              default: 0
          nargout (int, 1 or 2): optionally output new (cropped) volume size.
              return the grid_size only if nargout is 1, or (grid_size, new_vol_size)
              if narout is 2.
      Returns:
          grid_size only, if nargout is 1, or
          (grid_size, new_vol_size) if narout is 2
  
      See Also:
          grid()
  
      Contact:
          {adalca,klbouman}@csail.mit.edu
      """
  
      # parameter checking
      if not isinstance(vol_size, np.ndarray):
          vol_size = np.array(vol_size, 'int')
      if not isinstance(patch_size, np.ndarray):
          patch_size = np.array(patch_size, 'int')
      nb_dims = len(patch_size)   # number of dimensions
      if isinstance(patch_stride, int):
          patch_stride = np.repeat(patch_stride, nb_dims).astype('int')
      if isinstance(start_sub, int):
          start_sub = np.repeat(start_sub, nb_dims).astype('int')
  
      # adjacent patch overlap
      patch_overlap = patch_size - patch_stride
  
      # modified volume size if starting late
      mod_vol_size = vol_size - start_sub
      assert np.all(np.array(mod_vol_size) > 0), "New volume size is non-positive"
  
      # compute the number of patches
      # the final volume size will be
      # >> grid_size * patch_stride + patch_overlap
      # thus the part that is a multiplier of patch_stride is vol_size - patch_overlap
      patch_stride_multiples = mod_vol_size - patch_overlap # not sure?
      grid_size = np.floor(patch_stride_multiples / patch_stride).astype('int')
      assert np.all(np.array(grid_size) > 0), "Grid size is non-positive"
  
      if nargout == 1:
          return grid_size
      else:
          # new volume size based on how far the patches can reach
          new_vol_size = grid2volsize(grid_size, patch_size, patch_stride=patch_stride)
          return (grid_size, new_vol_size)
function_tokens: def gridsize ( vol_size , patch_size , patch_stride = 1 , start_sub = 0 , nargout = 1 ) : # parameter checking if not isinstance ( vol_size , np . ndarray ) : vol_size = np . array ( vol_size , 'int' ) if not isinstance ( patch_size , np . ndarray ) : patch_size = np . array ( patch_size , 'int' ) nb_dims = len ( patch_size ) # number of dimensions if isinstance ( patch_stride , int ) : patch_stride = np . repeat ( patch_stride , nb_dims ) . astype ( 'int' ) if isinstance ( start_sub , int ) : start_sub = np . repeat ( start_sub , nb_dims ) . astype ( 'int' ) # adjacent patch overlap patch_overlap = patch_size - patch_stride # modified volume size if starting late mod_vol_size = vol_size - start_sub assert np . all ( np . array ( mod_vol_size ) > 0 ) , "New volume size is non-positive" # compute the number of patches # the final volume size will be # >> grid_size * patch_stride + patch_overlap # thus the part that is a multiplier of patch_stride is vol_size - patch_overlap patch_stride_multiples = mod_vol_size - patch_overlap # not sure? grid_size = np . floor ( patch_stride_multiples / patch_stride ) . astype ( 'int' ) assert np . all ( np . array ( grid_size ) > 0 ) , "Grid size is non-positive" if nargout == 1 : return grid_size else : # new volume size based on how far the patches can reach new_vol_size = grid2volsize ( grid_size , patch_size , patch_stride = patch_stride ) return ( grid_size , new_vol_size )