From fc154bae222005f465ea60687e76d2b19eab9acb Mon Sep 17 00:00:00 2001 From: godsonj64 <108623780+godsonj64@users.noreply.github.com> Date: Sat, 21 Jun 2025 11:30:17 -0300 Subject: [PATCH] Fix overflow in color coherence vector calculation --- Script | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Script b/Script index 0c96a6e..3a0ec85 100644 --- a/Script +++ b/Script @@ -68,7 +68,9 @@ class ImageStyleTransfer: # Calculate Color Coherence Vector (CCV) def calculate_ccv(channel, threshold=10): blurred = cv2.GaussianBlur(channel, (5, 5), 0) - mask = np.abs(channel - blurred) > threshold + # Convert to a signed type before subtraction to avoid wrap-around + diff = channel.astype(np.int16) - blurred.astype(np.int16) + mask = np.abs(diff) > threshold coherent = np.sum(mask) incoherent = channel.size - coherent return coherent, incoherent