-
Notifications
You must be signed in to change notification settings - Fork 1
/
sky.py
69 lines (34 loc) · 1.21 KB
/
sky.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
import os
import numpy as np
import cv2
import matplotlib.pyplot as plt
import math
imgname = 'msu1'
img = cv2.imread('./{}.png'.format(imgname))
img = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
lapl = cv2.Laplacian(img[:,:,0], cv2.CV_64F, ksize=3)
# cv2.imwrite('./{}_lapl.png'.format(imgname), lapl)
y0 = 219.5
u0 = 17.5+128
v0 = -17.9+128
dy = 40.0
du = 40.0
dv = 40.0
Pcol = np.zeros(lapl.shape)
Ppos = np.zeros(lapl.shape)
rows, cols = lapl.shape
for i in range(rows):
for j in range(cols):
Pcol.itemset((i,j), math.exp(-((img[i,j,0]-y0)/dy)**2 - ((img[i,j,1]-u0)/du)**2 - ((img[i,j,2]-v0)/dv)**2) )
# cv2.imwrite('./{}_pcol.png'.format(imgname), Pcol*255)
for i in range(rows):
Ppos[i,:] = math.exp(-(i/float(rows+1))**2)
# cv2.imwrite('./{}_ppos.png'.format(imgname), Ppos*255)
# cv2.imwrite('./{}_col+pos.png'.format(imgname), Ppos*Pcol*255)
abslapl = abs(lapl)
abslapl = (abslapl.max()-abslapl)/abslapl.max()
# cv2.imwrite('./{}_lapl_abs.png'.format(imgname), abslapl*255)
# cv2.imwrite('./{}_col+pos+abslapl.png'.format(imgname), Ppos*Pcol*abslapl*255)
res = Ppos*Pcol*abslapl*255
ret, res1 = cv2.threshold(res, 90, 255, cv2.THRESH_BINARY)
cv2.imwrite('./{}_skymap.png'.format(imgname), res1)