-
Notifications
You must be signed in to change notification settings - Fork 1
/
CloudDetect.py
58 lines (42 loc) · 1.33 KB
/
CloudDetect.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
49
50
51
52
53
54
55
56
57
58
import numpy as np
import cv2
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
def Kmean(frame):
""" Detect Cloud in Frame
input: frame
output: frame with red pixel (cloud)
"""
# img = cv2.imread('images/Cloud6.png')
img = np.copy(frame)
imgClone = np.copy(img)
height, width, channel = img.shape
Z = img.reshape((-1, 3))
Z = np.float32(Z)
iterations = 10
epsilon = 1.0
criteria = (cv2.TERM_CRITERIA_EPS +
cv2.TERM_CRITERIA_MAX_ITER, iterations, epsilon)
K = 2
ret, label, center = cv2.kmeans(
Z, K, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
center = np.uint8(center)
res = center[label.flatten()]
res2 = res.reshape((img.shape))
# Sort by grayScale
# newCenter = center.reshape((1, -1, 3))
# grayCenter = cv2.cvtColor(newCenter, cv2.COLOR_BGR2GRAY)
# cloudPixel = center[np.argsort(grayCenter)[0][0]]
# Take Cloud mean
cloudMean = np.mean(center, axis=0)
cloudPixel = cloudMean
# print(cloudMean)
return cloudPixel
def CloudThreshold(frame, threshold):
img = np.copy(frame)
# print(threshold)
img[np.where((img >= threshold).all(axis=2))] = [0, 33, 166]
return img
def TotalCloud(frame, threshold):
total = frame[np.where((frame >= threshold).all(axis=2))].shape[0]
return total