-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQMIND Preprocessing.py
43 lines (30 loc) · 1.11 KB
/
QMIND Preprocessing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
@author: James Xie
"""
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('testimage.jpg')
plt.imshow(img)
def Preprocess(img, ball):
#Change colour space to HSV
#Note the image must originally be in BGR format. Depending on the image source, they may originally be in RGB.
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
ball = cv2.cvtColor(ball, cv2.COLOR_BGR2HSV)
#sharpness equalization
ImgSharp = cv2.Laplacian(img[:,:,2], cv2.CV_64F).var()
BallSharp = cv2.Laplacian(ball[:,:,2], cv2.CV_64F).var()
while abs(1 - BallSharp/ImageSharp) > 0.05:
if ImgSharp > BallSharp:
else:
#Intensity histogram equalization
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
img[:,:,2] = clahe.apply(img[:,:,2])
#img = cv2.cvtColor(img, cv2.COLOR_HSV2BGR)
#crop to square and resize to 256 x 256
h = min(img.shape[:2])
img = cv2.resize(img[0:h,0:h], (256,256))
#scale down the ball
return img
Preprocess(img, img)