-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexposure_correction.py
48 lines (29 loc) · 1 KB
/
exposure_correction.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
44
45
46
47
48
import cv2
import numpy as np
import scipy.sparse as spsparse
def get_unweighted_adjacency(img):
# create an unweighted adjacency matrix (4 neighbors)
rows = np.shape(img)[0]
cols = np.shape(img)[1]
h_connections = np.ones((cols, 1))
h_connections[-1] = 0;
diag_h = np.tile(h_connections, (rows, 1))
diag_h = diag_h[0:-1]
# print diag_h.shape
assert(diag_h.shape[0] == rows*cols - 1)
diag_v = np.ones((cols*(rows-1), 1))
# print diag_v.shape
assert(diag_v.shape[0] == rows*cols - cols)
diagonals = [diag_h.T, diag_v.T]
adj = spsparse.diags(diagonals, [1, cols], shape=(rows*cols, rows*cols), format='lil', dtype=np.uint8)
return adj
def main():
# img = cv2.imread("test_img.JPG", 0)
img = np.ones((600, 600))
adj_matrix = get_unweighted_adjacency(img)
# print adj_matrix[0, 1]
# cv2.namedWindow("output")
# dist_transform = cv2.distanceTransform(opening,cv2.DIST_L2,5)
# ret, sure_fg = cv2.threshold(dist_transform,0.7*dist_transform.max(),255,0)
if __name__ == "__main__":
main()