Merge pull request #422 from poipoi300/main

Minor ColorMatch improvement
This commit is contained in:
Jukka Seppänen 2025-11-22 17:43:04 +02:00 committed by GitHub
commit 7aafce8578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -98,6 +98,10 @@ https://github.com/hahnec/color-matcher/
"""
def colormatch(self, image_ref, image_target, method, strength=1.0, multithread=True):
# Skip unnecessary processing
if strength == 0:
return (image_target,)
try:
from color_matcher import ColorMatcher
except:
@ -118,9 +122,12 @@ https://github.com/hahnec/color-matcher/
image_target_np_i = images_target_np if batch_size == 1 else images_target[i].numpy()
image_ref_np_i = image_ref_np if image_ref.size(0) == 1 else images_ref[i].numpy()
try:
image_result = cm.transfer(src=image_target_np_i, ref=image_ref_np_i, method=method)
image_result = image_target_np_i + strength * (image_result - image_target_np_i)
image_result = cm.transfer(src=image_target_np_i, ref=image_ref_np_i, method=method) # Avoid potential blur when only the fully color-matched image is used
if strength != 1:
image_result = image_target_np_i + strength * (image_result - image_target_np_i)
return torch.from_numpy(image_result)
except Exception as e:
print(f"Thread {i} error: {e}")
return torch.from_numpy(image_target_np_i) # fallback