DHEIVER commited on
Commit
9d62c06
1 Parent(s): 14ef73d

Update preprocess.py

Browse files
Files changed (1) hide show
  1. preprocess.py +11 -4
preprocess.py CHANGED
@@ -1,6 +1,13 @@
1
  import cv2
 
2
 
3
- def unsharp_masking(img):
4
- gaussian = cv2.GaussianBlur(img, (0, 0), 2.0)
5
- img = cv2.addWeighted(img, 2.0, gaussian, -1.0, 0)
6
- return img
 
 
 
 
 
 
 
1
  import cv2
2
+ import numpy as np
3
 
4
+ def unsharp_masking(img, kernel_size=5, threshold=2.0):
5
+ if kernel_size % 2 == 0:
6
+ kernel_size += 1 # Ensure the kernel size is odd
7
+ gaussian = cv2.GaussianBlur(img, (kernel_size, kernel_size), 2.0)
8
+ unsharp_mask = cv2.addWeighted(img, threshold, gaussian, -1.0, 0)
9
+ # Clip the pixel values to the valid range [0, 255]
10
+ unsharp_mask = np.clip(unsharp_mask, 0, 255)
11
+ # Normalize the image to bring pixel values back to [0, 255]
12
+ cv2.normalize(unsharp_mask, unsharp_mask, 0, 255, cv2.NORM_MINMAX)
13
+ return unsharp_mask