-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_detection.py
116 lines (80 loc) · 2.38 KB
/
cloud_detection.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 8 17:22:11 2023
@author: suhai
"""
#For day 22/09/2019, there is no image for red
#code doesn't work for that day.
import file_selection
import numpy as np
import matplotlib.pyplot as plt
import cv2
start = '01/08/2019'
end = '14/08/2019'
R,G,B = file_selection.load_dates('all', start, end)
#plt.figure()
#plt.imshow(Ir16[0])
#plt.figure()
#plt.imshow(Vis8[0])
#plt.figure()
#plt.imshow(Vis6[0])
#col = np.stack((R[0],G[0],B[0]),axis=-1)
#plt.imshow(col)
#%%
cloud_removed = []
clouds =[]
for i in range(len(R)):
#R = cv2.GaussianBlur(R[i],(5,5),0)
#B = cv2.GaussianBlur(G[i],(5,5),0)
#G = cv2.GaussianBlur(B[i],(5,5),0)
red = R[i]
blue = B[i]
green = G[i]
#global threshold
b_1 = cv2.inRange(blue, 120, 255)
g_1 = cv2.inRange(green, 120, 255)
#add all the threshold for the global threshold
img_1 = cv2.add(g_1,b_1)
#first segment, north pole, notable change in blue
b_seg1 = blue[0:500,0:3712]
blue1 = cv2.inRange(b_seg1, 55, 120)
#second segment, south pole, notable change in blue and green
b_seg2 = blue[3000:3712,0:3712]
blue2 = cv2.inRange(b_seg2, 80, 120)
g_seg2 = green[3000:3712,0:3712]
green2 = cv2.inRange(g_seg2, 80, 120)
img_2 = cv2.add(blue2,green2)
#add border
added1 = cv2.copyMakeBorder(blue1, 0, 3212, 0, 0, cv2.BORDER_CONSTANT)
added2 = cv2.copyMakeBorder(img_2, 3000, 0, 0, 0, cv2.BORDER_CONSTANT)
#add segments to global threshold
one = cv2.add(img_1,added1)
two = cv2.add(one,added2)
#dilation
#kernel = np.ones((5,5),np.uint8)
#two= cv2.dilate(two,kernel,iterations = 1)
clouds.append(two)
#subtract cloud in each colour
red_c = cv2.subtract(red, two)
green_c = cv2.subtract(green, two)
blue_c = cv2.subtract(blue, two)
#create image
col = np.stack((red_c,green_c,blue_c),axis=-1)
#append to list
cloud_removed.append(col)
#%%
#convert to array
cloud_removed1 = np.array(cloud_removed)
clouds1 = np.array(clouds)
#%%
clouds2 =[]
#conver clouds to binary instead of 0 to 255
for i in range(len(clouds)):
img = clouds[i]
img = np.array(img/img.max(),dtype=np.uint8)
clouds2.append(img)
#plt.figure()
#plt.imshow(cloud_removed[0])
#col = np.stack((R[0],G[0],B[0]),axis=-1)
#plt.figure()
#plt.imshow(col)