def lightfield(rgb): (_,w,_) = rgb.shape # color balance cb = gray_world(rgb).clip(0.,1.) # estimate background rf = uniform_filter(cb,w/3) # subtract it from image sb = cb - rf # rescale sb = (sb - sb.min()) / sb.ptp() # gamma, brightness sb = np.power(sb,4./3.) * 2 # apply unsharp mask s = 3 um = gaussian_filter(sb,10) sharp = ((s / (s - 1)) * (sb - um / s)).clip(0.,1.) return sharp
def correct_image(self,image): """ Correct an RGB image. Parameters ---------- image : ndarray 3-channel color (RGB) image Returns ------- corrected image : ndarray corrected image (corrected for illumination and/or color balance and/or brightness. does not clip out of gamut colors. """ if self.color_balance: new_rgb = gray_world(image) else: new_rgb = image return (new_rgb / self.lightmap) * self.lightmap.ptp() * self.brightness