윤영준 윤영준 2023-07-06
test code for preprocessing
@8b0e9fe8a626714fc2e698a810ad578b606d7aa1
 
binary mask map test.py (added)
+++ binary mask map test.py
@@ -0,0 +1,43 @@
+import numpy as np
+import cv2
+import glob
+
+def shift_img(img, x, y):
+    M = np.float32([[1, 0, x],
+
+                    [0, 1, y]])
+
+    shifted = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))
+
+    return shifted
+
+def binary_diff_mask(clean, dirty, thresold=0.2):
+    # this parts corrects gamma, and always remember, sRGB values are not in linear scale with lights intensity,
+    clean = np.power(clean, 1/2.2)
+    dirty = np.power(dirty, 1/2.2)
+
+    # averaged_per_pixel = np.abs(dirty / shift_img(clean, 5, 0) - 1)
+    # print(averaged_per_pixel)
+    diff = np.abs(clean - dirty)
+
+    bin_diff = (diff > thresold).astype(np.uint8)
+
+    return bin_diff
+
+clean = glob.glob("data/source/clean/*.png")
+clean = sorted(clean)
+dirty = glob.glob("data/source/dirty/*.png")
+dirty = sorted(dirty)
+
+clean_img = cv2.imread(clean[0])
+dirty_img = cv2.imread(dirty[0])
+
+binary_diff_mask_img = binary_diff_mask(dirty_img/255, clean_img/255, thresold=0.05)
+
+k = 40
+
+for i in range(k*2):
+    print(i)
+    clean_img_copy = shift_img(clean_img, (i-k)/4, 0)
+    binary_diff_mask_img = binary_diff_mask(dirty_img / 255, clean_img_copy / 255, thresold=0.2)
+    cv2.imwrite(f"test/test_img{(i-k)/4}.png", binary_diff_mask_img*255)
Add a comment
List