code: def linear_density(im, bins=25, voxel_size=1, log=False):
      r
      x = im[im > 0]
      h = list(sp.histogram(x, bins=bins, density=True))
      h = _parse_histogram(h=h, voxel_size=voxel_size)
      cld = namedtuple('linear_density_function',
                       ('L', 'pdf', 'cdf', 'relfreq',
                        'bin_centers', 'bin_edges', 'bin_widths'))
      return cld(h.bin_centers, h.pdf, h.cdf, h.relfreq,
                 h.bin_centers, h.bin_edges, h.bin_widths)
docs: r"""
      Determines the probability that a point lies within a certain distance
      of the opposite phase *along a specified direction*
  
      This relates directly the radial density function defined by Torquato [1],
      but instead of reporting the probability of lying within a stated distance
      to the nearest solid in any direciton, it considers only linear distances
      along orthogonal directions.The benefit of this is that anisotropy can be
      detected in materials by performing the analysis in multiple orthogonal
      directions.
  
      Parameters
      ----------
      im : ND-array
          An image with each voxel containing the distance to the nearest solid
          along a linear path, as produced by ``distance_transform_lin``.
      bins : int or array_like
          The number of bins or a list of specific bins to use
      voxel_size : scalar
          The side length of a voxel.  This is used to scale the chord lengths
          into real units.  Note this is applied *after* the binning, so
          ``bins``, if supplied, should be in terms of voxels, not length units.
  
      Returns
      -------
      result : named_tuple
  
      References
      ----------
      [1] Torquato, S. Random Heterogeneous Materials: Mircostructure and
      Macroscopic Properties. Springer, New York (2002)