-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadTiff.m
54 lines (44 loc) · 2.2 KB
/
uploadTiff.m
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
function [ images, CMAP, REFMAT, BBOX ] = uploadTiff(directory)
% This function upload all .TIFF image with the matlab function geotiffread()
% present in the given "directory" path. Additionaly it converted the images
% it into double precision. Moreover it gives all CMPA, REFMAT and BBOX,
% please refer to documentation of geotiffread. ("help geotiffread").
%
% The folder should be structure as follows:
% DIRECTORY: -data/
% |__
% SUBDFOLDERS: 15-02-2019 16-02-2019
% DIFFERENTS BANDS: |__ 2018-03-12, Sentinel-2A L1C, B03.tiff
%
%
% /!\ this code work properly for the images names downloded from EO XX
% the last three digit of the bands should given the bands name, as
% B04, otherwise this code is still not adapted to encode the bands
% with the rigth name.
subfolders = dir(directory); % List all files and folders in directory
subfolders(1:2) = []; % delete the folders '.' and '..'
% Loop for all date directory
for n = 1:length(subfolders) % For all documents in directory
if subfolders(n).isdir % Basicly Ingore the .gejson file (only directory counts)
abs_path = strcat(subfolders(n).folder,'/', subfolders(n).name);
files = dir(abs_path); % All geotiff image of a date should be here
% Gives the date for bands from the same date
images(n).date = subfolders(n).name;
% loop over al tiff images
for k = 1:length(files)
if ~files(k).isdir
% path to single .tiff image
abs_path = strcat(files(k).folder,'/', files(k).name);
% Name of the band (last three digit of the path)
BandsName = files(k).name(end-6:end-4);
% read .TIFF and add bands to the structure bands
[ images(n).(BandsName), CMAP(n).(BandsName),...
REFMAT(n).(BandsName), BBOX(n).(BandsName) ] ...
= geotiffread(abs_path);
% Convert image to double precision
images(n).(BandsName) = im2double(images(n).(BandsName));
end
end
end
end
end