code: def stretch_hist_equalize(self, approximate=False):
          
          logger.info("Perform a histogram equalized contrast stretch.")
  
          nwidth = 2048.
          logger.debug("Make histogram bins having equal amount of data, " +
                       "using numpy percentile function:")
  
          def _band_hist(band_data):
              cdf = da.arange(0., 1., 1. / nwidth, chunks=nwidth)
              if approximate:
                  # need a 1D array
                  flat_data = band_data.ravel()
                  # replace with nanpercentile in the future, if available
                  # dask < 0.17 returns all NaNs for this
                  bins = da.percentile(flat_data[da.notnull(flat_data)],
                                       cdf * 100.)
              else:
                  bins = dask.delayed(np.nanpercentile)(band_data, cdf * 100.)
                  bins = da.from_delayed(bins, shape=(nwidth,), dtype=cdf.dtype)
              res = dask.delayed(np.interp)(band_data, bins, cdf)
              res = da.from_delayed(res, shape=band_data.shape,
                                    dtype=band_data.dtype)
              return res
  
          band_results = []
          for band in self.data['bands'].values:
              if band == 'A':
                  continue
              band_data = self.data.sel(bands=band)
              res = _band_hist(band_data.data)
              band_results.append(res)
  
          if 'A' in self.data.coords['bands'].values:
              band_results.append(self.data.sel(bands='A'))
          self.data.data = da.stack(band_results,
                                    axis=self.data.dims.index('bands'))
docs: Stretch the current image's colors through histogram equalization.
  
          Args:
              approximate (bool): Use a faster less-accurate percentile
                                  calculation. At the time of writing the dask
                                  version of `percentile` is not as accurate as
                                  the numpy version. This will likely change in
                                  the future. Current dask version 0.17.