Formatting fixes

This commit is contained in:
MMaker 2023-11-15 20:24:16 -05:00
parent 78a01e432e
commit d2ee9d24ac
Signed by: mmaker
GPG Key ID: CCE79B8FEDA40FB2
3 changed files with 6 additions and 8 deletions

View File

@ -6,4 +6,4 @@ NODE_CLASS_MAPPINGS = {
NODE_DISPLAY_NAME_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = {
"MMakerColorEnhance": "Color Enhance", "MMakerColorEnhance": "Color Enhance",
} }

View File

@ -6,9 +6,9 @@ import imageio.core.util
imageio.core.util._precision_warn = lambda *args, **kwargs: None imageio.core.util._precision_warn = lambda *args, **kwargs: None
def color_enhance(arr, strength: float = 1) -> Image.Image: def color_enhance(arr, strength: float = 1) -> Image.Image:
lch = skimage.color.lab2lch(lab=skimage.color.rgb2lab(rgb=np.array(arr, dtype=np.uint8))) lch = skimage.color.lab2lch(lab=skimage.color.rgb2lab(rgb=np.array(arr, dtype=np.uint8)))
lch[:, :, 1] *= 100/(lerp(100, lch[:, :, 1].max(), strength)) # Normalize chroma component lch[:, :, 1] *= 100/(lerp(100, lch[:, :, 1].max(), strength)) # Normalize chroma component
return Image.fromarray(np.array(skimage.color.lab2rgb(lab=skimage.color.lch2lab(lch=lch)) * 255, dtype=np.uint8)) return Image.fromarray(np.array(skimage.color.lab2rgb(lab=skimage.color.lch2lab(lch=lch)) * 255, dtype=np.uint8))
def lerp(a: float, b: float, t: float) -> float: def lerp(a: float, b: float, t: float) -> float:
return (1 - t) * a + t * b return (1 - t) * a + t * b

View File

@ -17,10 +17,8 @@ class ScriptPostprocessingColorEnhance(scripts_postprocessing.ScriptPostprocessi
def process(self, pp: scripts_postprocessing.PostprocessedImage, strength): def process(self, pp: scripts_postprocessing.PostprocessedImage, strength):
if strength == 0: if strength == 0:
return return
info_bak = {} if not hasattr(pp.image, "info") else pp.image.info info_bak = {} if not hasattr(pp.image, "info") else pp.image.info
pp.image = lib.color_enhance(pp.image, strength) pp.image = lib.color_enhance(pp.image, strength)
pp.image.info = info_bak pp.image.info = info_bak
pp.info["Color Enhance"] = strength pp.info["Color Enhance"] = strength