-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
61 lines (45 loc) · 1.76 KB
/
utils.py
File metadata and controls
61 lines (45 loc) · 1.76 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import numpy as np
from matplotlib import pyplot as plt
import cv2
def load_image(nom, is_color):
# Channel BGR
if is_color:
img = cv2.imread(nom, cv2.IMREAD_COLOR)
else:
img = cv2.imread(nom, cv2.IMREAD_GRAYSCALE)
return img
def inverse_image(I):
# I : cv2 img
return 255 - I
def BGR_to_HSV(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
def BGR_to_Lab(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
# http://www.pyimagesearch.com/2014/01/22/clever-girl-a-guide-to-utilizing-color-histograms-for-computer-vision-and-image-search-engines/
def BGR_histogram(bgr_img, black_and_white_img):
# plot a 2D color histogram for red and green
hist = cv2.calcHist([bgr_img], [2, 1], black_and_white_img[:, :, 0],
[32, 32], [0, 256, 0, 256])
return hist
def HSV_histogram(hsv_img, black_and_white_img):
hist = cv2.calcHist([hsv_img], [0, 1], black_and_white_img[:, :, 0],
[180, 256], [0, 180, 0, 256])
return hist
def Lab_histogram(lab_img, black_and_white_img):
hist = cv2.calcHist([lab_img], [1, 2], black_and_white_img[:, :, 0],
[256, 256], [0, 256, 0, 256])
return hist
if __name__ == '__main__':
# data/Ground_Truth/GroundT_FacePhoto/06Apr03Face.png
# data/Pratheepan_Dataset/FacePhoto/06Apr03Face.jpg
bgr_img = load_image("data/Pratheepan_Dataset/FacePhoto/06Apr03Face.jpg",
True)
hsv_img = BGR_to_Lab(bgr_img)
black_and_white_img = load_image(
"data/Ground_Truth/GroundT_FacePhoto/06Apr03Face.png", True)
'''cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()'''
histo = Lab_histogram(hsv_img, black_and_white_img)
print(histo)
print(histo.shape)