Skip to content

Commit db9f01f

Browse files
authored
Add files via upload
1 parent 3e4d5b0 commit db9f01f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+7296
-0
lines changed

BufferMasks.m

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function [cloud,shadow,snow] = BufferMasks(pcloud,cdpix,pshadow,csdpix,psnow,sdpix)
2+
% BUFFERMASKS Dilate cloud/cloud shadow/snow with cdpix/csdpix/sdpix with
3+
% default value of 3/3/3.
4+
%
5+
% Syntax
6+
%
7+
% [cloud,shadow,snow] =
8+
% BufferMasks(pcloud,cdpix,pshadow,csdpix,psnow,sdpix)
9+
%
10+
% Description
11+
%
12+
% Dilate cloud/cloud shadow/snow with cdpix/csdpix/sdpix with
13+
% default value of 3/3/3.
14+
%
15+
% Input arguments
16+
% pcloud Cloud mask.
17+
% cldpix Dilated number of pixels for cloud with default value of 3.
18+
% pshadow Cloud shadow mask.
19+
% sdpix Dilated number of pixels for cloud shadow value of 3.
20+
% psnow Snow mask.
21+
% snpix Dilated number of pixels for snow value of 3.
22+
%
23+
% Output arguments
24+
%
25+
% cloud Final dilated cloud mask.
26+
% shadow Final dilated cloud shadow mask.
27+
% snow Final dilated snow mask.
28+
%
29+
% Example
30+
%
31+
% [cloud,shadow,snow] =
32+
% BufferMasks(pcloud,3,pshadow,3,psnow,3);
33+
%
34+
%
35+
% Author: Shi Qiu ([email protected])
36+
% Date: 2. November, 2017
37+
38+
% buffer cloud
39+
if cdpix>0
40+
CEs=strel('square',2*cdpix+1);
41+
cloud=imdilate(pcloud,CEs);
42+
clear pcloud CEs cdpix;
43+
else
44+
cloud=pcloud;
45+
clear pcloud
46+
end
47+
% buffer cloud shadow
48+
if csdpix>0
49+
CSEs=strel('square',2*csdpix+1);
50+
shadow=imdilate(pshadow,CSEs);
51+
clear pshadow CSEs csdpix;
52+
else
53+
shadow=pshadow;
54+
clear pshadow
55+
end
56+
% buffer snow
57+
if sdpix>0
58+
SEs=strel('square',2*sdpix+1);
59+
snow=imdilate(psnow,SEs);
60+
clear psnow SEs sdpix;
61+
else
62+
snow=psnow;
63+
clear psnow
64+
end
65+
end
66+

CDI.m

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function cdi = CDI(S2band7,S2band8,S2band8A)
2+
%CDI This is used seprate bright surface from cloud by following David,
3+
%2018 RSE
4+
if ~isempty(S2band7)&&~isempty(S2band8)
5+
ratio_8A_8 = S2band8./S2band8A;
6+
clear S2band8;
7+
ratio_8A_7 = S2band7./S2band8A;
8+
clear S2band7 S2band8A;
9+
10+
std_ratio_8A_8 =stdfilt(ratio_8A_8, true(7));
11+
clear ratio_8A_8;
12+
var_ratio_8A_8 = std_ratio_8A_8 .^2;
13+
clear std_ratio_8A_8;
14+
15+
std_ratio_8A_7 = stdfilt(ratio_8A_7, true(7));
16+
clear ratio_8A_7;
17+
var_ratio_8A_7 = std_ratio_8A_7 .^2;
18+
clear std_ratio_8A_7;
19+
20+
cdi = (var_ratio_8A_7-var_ratio_8A_8)./(var_ratio_8A_8+var_ratio_8A_7);
21+
22+
% dim = size(cdi);
23+
% cdi = imresize(cdi,1/7,'box');
24+
% cdi = ordfilt2(cdi,1,ones(3,3));
25+
% cdi = imresize(cdi,dim,'nearest');
26+
% clear dim;
27+
28+
29+
% h = fspecial('average', 21);
30+
% cdi = filter2(h, cdi);
31+
else
32+
cdi = [];
33+
end
34+
end
35+
36+

CheckImagesPath.m

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
function [num_all_images, sensors, paths, info_count_text] = CheckImagesPath(path_data)
2+
%CHECKIMAGEPATH Ensure the input path is right to find a Landsats 4-8, and
3+
%Sentinel 2 image(s).
4+
% path_data - the input path
5+
6+
% searching deeps. 0 is default.
7+
[image_types_paths] = CheckImagePath(path_data,0);
8+
9+
% all count info foe searched images at current folder.
10+
num_all_images = size(image_types_paths,1);
11+
num_L4_tm = 0;
12+
num_L5_tm = 0;
13+
num_L6_tm = 0;
14+
num_L7_tm_plus = 0;
15+
num_L8_oli_tirs = 0;
16+
num_S2A_msi = 0;
17+
num_S2B_msi = 0;
18+
19+
% key info: the senor and path are needed as outputs, the first one is
20+
% to determine the default parameters for Fmask, and the second one is
21+
% to determine the path loading all data.
22+
sensors = [];
23+
paths = [];
24+
info_count_text = [];
25+
26+
for i_all = 1:num_all_images
27+
% c: current.
28+
cimage_sensor = image_types_paths{i_all,1};
29+
cimage_num = image_types_paths{i_all,2};
30+
cimage_type = Convert2ImageType(cimage_sensor,cimage_num);
31+
clear cimage_num;
32+
cimage_path = image_types_paths{i_all,3};
33+
switch cimage_type
34+
case {'Landsat 4 TM'}
35+
num_L4_tm=num_L4_tm+1;
36+
case {'Landsat 5 TM'}
37+
num_L5_tm=num_L5_tm+1;
38+
case {'Landsat 6 TM'}
39+
num_L6_tm=num_L6_tm+1;
40+
case {'Landsat 7 ETM+'}
41+
num_L7_tm_plus=num_L7_tm_plus+1;
42+
case {'Landsat 8 OLI/TIRS'}
43+
num_L8_oli_tirs=num_L8_oli_tirs+1;
44+
case {'Sentinel 2A MSI'}
45+
% further check Sentinel 2 image folder, see there is
46+
% .SAFE.
47+
if contains(cimage_path,'.SAFE')
48+
num_S2A_msi=num_S2A_msi+1;
49+
else
50+
cimage_sensor = [];% no available Sentinel 2 data.
51+
end
52+
case {'Sentinel 2B MSI'}
53+
% see there is .SAFE.
54+
if contains(cimage_path,'.SAFE')
55+
num_S2B_msi=num_S2B_msi+1;
56+
else
57+
cimage_sensor = [];% no available Sentinel 2 data.
58+
end
59+
end
60+
if ~isempty(cimage_sensor)
61+
sensors = [sensors;{cimage_sensor}];
62+
paths = [paths;{cimage_path}];
63+
end
64+
clear cimage_sensor;
65+
end
66+
% renew num_all_images
67+
num_all_images = length(sensors);
68+
% used to notice user.
69+
text_line = 0;
70+
% multide
71+
if isequal(num_all_images,num_L4_tm)||...
72+
isequal(num_all_images,num_L5_tm)||...
73+
isequal(num_all_images,num_L6_tm)||...
74+
isequal(num_all_images,num_L7_tm_plus)||...
75+
isequal(num_all_images,num_L8_oli_tirs)||...
76+
isequal(num_all_images,num_S2A_msi)||...
77+
isequal(num_all_images,num_S2B_msi)
78+
% only for 1 type image
79+
if num_L4_tm > 0
80+
text_line = text_line+1;
81+
info_count_text{text_line} = sprintf('%s Landsat 4 TM images are found at ''%s''\n',...
82+
num2str(num_L4_tm),path_data);
83+
end
84+
if num_L5_tm > 0
85+
text_line = text_line+1;
86+
info_count_text{text_line} = sprintf('%s Landsat 5 TM images are found at ''%s''\n',...
87+
num2str(num_L5_tm),path_data);
88+
end
89+
if num_L6_tm > 0
90+
text_line = text_line+1;
91+
info_count_text{text_line} = sprintf('%s Landsat 6 TM images are found at ''%s''\n',...
92+
num2str(num_L6_tm),path_data);
93+
end
94+
if num_L7_tm_plus > 0
95+
text_line = text_line+1;
96+
info_count_text{text_line} = sprintf('%s Landsat 7 ETM+ images are found at ''%s''\n',...
97+
num2str(num_L7_tm_plus),path_data);
98+
end
99+
if num_L8_oli_tirs > 0
100+
text_line = text_line+1;
101+
info_count_text{text_line} = sprintf('%s Landsat 8 OLI/TIRS images are found at ''%s''\n',...
102+
num2str(num_L8_oli_tirs),path_data);
103+
end
104+
if num_S2A_msi > 0
105+
text_line = text_line+1;
106+
info_count_text{text_line} = sprintf('%s Sentinel 2A MSI images are found at ''%s''\n',...
107+
num2str(num_S2A_msi),path_data);
108+
end
109+
if num_S2B_msi > 0
110+
text_line = text_line+1;
111+
info_count_text{text_line} = sprintf('%s Sentinel 2B MSI images are found at ''%s''\n',...
112+
num2str(num_S2B_msi),path_data);
113+
end
114+
else
115+
text_line = text_line+1;
116+
info_count_text{text_line} = sprintf(...
117+
'A total of %s images (as follows) are found at ''%s''\n',...
118+
num2str(num_all_images), path_data);
119+
if num_L4_tm > 0
120+
text_line = text_line+1;
121+
info_count_text{text_line} = sprintf('%s Landsat 4 TM images\n',...
122+
num2str(num_L4_tm));
123+
end
124+
if num_L5_tm > 0
125+
text_line = text_line+1;
126+
info_count_text{text_line} = sprintf('%s Landsat 5 TM images\n',...
127+
num2str(num_L5_tm));
128+
end
129+
if num_L6_tm > 0
130+
text_line = text_line+1;
131+
info_count_text{text_line} = sprintf('%s Landsat 6 TM images\n',...
132+
num2str(num_L6_tm));
133+
end
134+
if num_L7_tm_plus > 0
135+
text_line = text_line+1;
136+
info_count_text{text_line} = sprintf('%s Landsat 7 ETM+ images\n',...
137+
num2str(num_L7_tm_plus));
138+
end
139+
if num_L8_oli_tirs > 0
140+
text_line = text_line+1;
141+
info_count_text{text_line} = sprintf('%s Landsat 8 OLI/TIRS images\n',...
142+
num2str(num_L8_oli_tirs));
143+
end
144+
if num_S2A_msi > 0
145+
text_line = text_line+1;
146+
info_count_text{text_line} = sprintf('%s Sentinel 2A MSI images\n',...
147+
num2str(num_S2A_msi));
148+
end
149+
if num_S2B_msi > 0
150+
text_line = text_line+1;
151+
info_count_text{text_line} = sprintf('%s Sentinel 2B MSI images\n',...
152+
num2str(num_S2B_msi));
153+
end
154+
end
155+
156+
% if no data is found, give mention info.
157+
if isempty(sensors)
158+
text_line = text_line+1;
159+
info_count_text{text_line} = sprintf('%s available images are found at ''%s''\n',...
160+
'0',path_data);
161+
text_line = text_line+1;
162+
info_count_text{text_line} = sprintf('Please ensure the path is correct\n');
163+
end
164+
% fprintf(info_count);
165+
end
166+
167+
function [image_types_paths] = CheckImagePath(path_data,subfolder_level)
168+
%CHECKIMAGEPATH Ensure the input path is right to find a Landsats 4-8, and
169+
%Sentinel 2 image(s).
170+
% path_data - the input path
171+
% subfolder_level - the level of subfolders that can be used to limit
172+
% searching deeps. 0 is default.
173+
174+
% If the searching deeps are more than 5, stop and return;
175+
if subfolder_level > 5
176+
image_types_paths = [];
177+
return;
178+
end
179+
image_types_paths = [];
180+
% first search the image(s) at current folder.image_types_paths
181+
[sensor,num_Lst,~,~] = LoadSensorType(path_data);
182+
if isempty(sensor)
183+
% if no available image at current folder,
184+
% and search its subfolders.
185+
subfolders = dir(path_data);
186+
for i_sub=1:length(subfolders)
187+
% filter out the file names starting with '.', that is not
188+
% right folder (system crashes).
189+
if strcmp(subfolders(i_sub).name(1),'.')
190+
continue;
191+
end
192+
% go to search the images at each subfolder
193+
path_subfoler = fullfile(subfolders(i_sub).folder,...
194+
subfolders(i_sub).name);
195+
[image_types_paths_sub] = CheckImagePath(path_subfoler,subfolder_level+1);
196+
if ~isempty(image_types_paths_sub)
197+
image_types_paths =[image_types_paths;image_types_paths_sub];
198+
end
199+
end
200+
201+
else
202+
% successfully searched a supported image.
203+
% and, return the sensor and the image path
204+
image_types_paths = [image_types_paths;{sensor,num_Lst,path_data}];
205+
end
206+
end
207+
function image_type = Convert2ImageType(sensor,num_Lst)
208+
% CONVERT@IMAGETYPE Contruct image type from the sensor and num
209+
210+
switch sensor
211+
case 'L_TM'
212+
image_type = ['Landsat ',num_Lst,' TM'];
213+
case 'L_ETM_PLUS'
214+
image_type = ['Landsat ',num_Lst,' ETM+'];
215+
case 'L_OLI_TIRS'
216+
image_type = ['Landsat ',num_Lst,' OLI/TIRS'];
217+
case 'S_MSI'
218+
image_type = ['Sentinel ',num_Lst,' MSI'];
219+
otherwise
220+
image_type=[];
221+
% error(['Errors occur when searching images at ''', path_data],'''.');
222+
end
223+
end
224+

0 commit comments

Comments
 (0)