From 6abac2e4706a3d937420213e01468bae10cc2017 Mon Sep 17 00:00:00 2001 From: bymyself Date: Mon, 20 May 2024 14:32:15 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Use=20dynamic=20contrast=20?= =?UTF-8?q?in=20Color=20Correct=20(#180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change contrast_adjustment_tensor method to change contrast dynamically * Switch to Adobe RGB color space --- nodes/image_processing.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nodes/image_processing.py b/nodes/image_processing.py index 6b15eaf..f7467cb 100644 --- a/nodes/image_processing.py +++ b/nodes/image_processing.py @@ -86,7 +86,14 @@ class MTB_ColorCorrect: @staticmethod def contrast_adjustment_tensor(image, contrast): - contrasted = (image - 0.5) * contrast + 0.5 + r, g, b = image.unbind(-1) + + # Using Adobe RGB luminance weights. + luminance_image = 0.33 * r + 0.71 * g + 0.06 * b + luminance_mean = torch.mean(luminance_image.unsqueeze(-1)) + + # Blend original with mean luminance using contrast factor as blend ratio. + contrasted = image * contrast + (1.0 - contrast) * luminance_mean return torch.clamp(contrasted, 0.0, 1.0) @staticmethod