def equalize_hist(image, nbins=256, mask=None):
 if (mask is not None):
  mask = np.array(mask, dtype=bool)
  (cdf, bin_centers) = cumulative_distribution(image[mask], nbins)
 else:
  (cdf, bin_centers) = cumulative_distribution(image, nbins)
 out = np.interp(image.flat, bin_centers, cdf)
 return out.reshape(image.shape)

def equalize_hist ( image , nbins = 256 , mask = None ) : if ( mask is not None ) : mask = np . array ( mask , dtype = bool ) ( cdf , bin_centers ) = cumulative_distribution ( image [ mask ] , nbins ) else : ( cdf , bin_centers ) = cumulative_distribution ( image , nbins ) out = np . interp ( image . flat , bin_centers , cdf ) return out . reshape ( image . shape )
return image after histogram equalization .