-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoad_clouds.py
180 lines (124 loc) · 4.68 KB
/
Load_clouds.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 6 17:06:07 2023
@author: suhail
"""
import file_selection
import numpy as np
import cv2
def clouds(week):
"""
This function uses file_selection to load in the range of images.
Then taking those image and perform thresholding to find clouds in each
of the images and return data about the locations of the clouds.
The function produce the coloured images with the clouds replace with
the value zero showing as black.
"""
#load files
R,G,B = file_selection.load_by_week(week, separate = True)
#empty array for data
cloud_removed = []
clouds =[]
for i in range(len(R)):
#loop each image
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 to segments
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)
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 =[]
#change max value 255 to 1.
for i in range(len(clouds1)):
img = clouds[i]
img = np.array(img/img.max(),dtype=np.uint8)
clouds2.append(img)
clouds2 = np.array(clouds2)
return clouds2 , cloud_removed1
def Load_clouds(start,end):
"""
This function uses file_selection to load in the range of images.
Then taking those image and perform thresholding to find clouds in each
of the images and return data about the locations of the clouds.
The function produce the coloured images with the clouds replace with
the value zero showing as black.
"""
#load files
R,G,B = file_selection.load_datetimes_three_colour(start, end)
#empty array for data
cloud_removed = []
clouds =[]
for i in range(len(R)):
#loop each image
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 to segments
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)
clouds.append(one)
#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 =[]
#change max value 255 to 1.
for i in range(len(clouds1)):
img = clouds[i]
img = np.array(img/img.max(),dtype=np.uint8)
clouds2.append(img)
clouds2 = np.array(clouds2)
return clouds2 , cloud_removed1