code: def porosity(im):
      r
      im = sp.array(im, dtype=int)
      Vp = sp.sum(im == 1)
      Vs = sp.sum(im == 0)
      e = Vp/(Vs + Vp)
      return e
docs: r"""
      Calculates the porosity of an image assuming 1's are void space and 0's are
      solid phase.
  
      All other values are ignored, so this can also return the relative
      fraction of a phase of interest.
  
      Parameters
      ----------
      im : ND-array
          Image of the void space with 1's indicating void space (or True) and
          0's indicating the solid phase (or False).
  
      Returns
      -------
      porosity : float
          Calculated as the sum of all 1's divided by the sum of all 1's and 0's.
  
      See Also
      --------
      phase_fraction
  
      Notes
      -----
      This function assumes void is represented by 1 and solid by 0, and all
      other values are ignored.  This is useful, for example, for images of
      cylindrical cores, where all voxels outside the core are labelled with 2.
  
      Alternatively, images can be processed with ``find_disconnected_voxels``
      to get an image of only blind pores.  This can then be added to the orignal
      image such that blind pores have a value of 2, thus allowing the
      calculation of accessible porosity, rather than overall porosity.