-
Notifications
You must be signed in to change notification settings - Fork 9
/
CSPprocessEZDetach.m
114 lines (98 loc) · 3.84 KB
/
CSPprocessEZDetach.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
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
%First, load paths
CSPloadPaths
%Set timezone
timezone = 'AEDT';
%Read files in directory
EZdir = 'C:\Users\z2273773\OneDrive - UNSW\RESEARCH2\CoastSnap\EZDetach';
files1 = dir([EZdir filesep '*.jpg']);files2 = dir([EZdir filesep '*.jpeg']);
files = [files1; files2];
dbfile = fullfile([DB_path filesep 'CoastSnapDB.xlsx']);
[data,txt] = xlsread(dbfile,'database');
lastrow = length(data)+1; %Last row where data exists in the CoastSnapDB
%Get lat lon of sites
lats = NaN(length(files),1);
lons = NaN(length(files),1);
sites = {'manly','nthnarra','blacksmiths','byron','tomakin','broulee'};
UTM = {'56 H','56 H','56 H','56 J','56 H','56 H'};
sitelat = NaN(length(sites),1);
sitelon = NaN(length(sites),1);
for i = 1:length(sites)
siteDB = CSPreadSiteDB(sites{i}); %Read metadata
[sitelat(i),sitelon(i)]=utm2deg(siteDB.origin.eastings,siteDB.origin.northings,UTM{i});
end
%Loop through images to classify accordingly
distthresh = 0.05;
for i = 1:length(files)
lastrow = lastrow+1;
fname = files(i).name
C = strsplit(fname,'_');
exif = imfinfo(fullfile(EZdir,fname));
if isfield(exif,'DateTime') %If there is Exif data on the capture time
time = datenum(exif.DateTime,'yyyy:mm:dd HH:MM:SS');
timequality = 1; %Trust the exif data
else
time = datenum(C{2},'yyyymmddHHMM'); %Time email was sent
timequality = 2; %Have less trust in time coming from email time sent
end
user = C{3};
subject = C{4};
C2 = strsplit(user,'@'); %If user is an email address, take part before @ sign
user = C2{1};
if isfield(exif,'GPSInfo')
if isfield(exif.GPSInfo,'GPSLatitude')
lat = exif.GPSInfo.GPSLatitude;
if lat(3)==60
lat(2) = lat(2)+1;
lat(3) = 0;
end
lats = dms2degrees(lat);
lons = dms2degrees(exif.GPSInfo.GPSLongitude);
dists = sqrt((-lats-sitelat).^2+(lons-sitelon).^2);
I = find(dists<distthresh);
if length(I)==1;
thissite = sites{I};
else thissite = 'unclassified';
end
else thissite = 'unclassified';
end
else
thissite = 'unclassified';
end
%Next try to classify sites based on subject
if strcmp(thissite,'unclassified');
if ~isempty(strfind(lower(subject),'manly'))
thissite = 'manly';
elseif ~isempty(strfind(lower(subject),'narra'))
thissite = 'nthnarra';
elseif ~isempty(strfind(lower(subject),'byron'))
thissite = 'byron';
elseif ~isempty(strfind(lower(subject),'black'))
thissite = 'blacksmiths';
elseif ~isempty(strfind(lower(subject),'broulee'))
thissite = 'broulee';
elseif ~isempty(strfind(lower(subject),'tomakin'))
thissite = 'tomakin';
end
%Next try to classify sites based on user
if ~isempty(strfind(lower(user),'gnarf'))
thissite = 'nthnarra';
elseif ~isempty(strfind(lower(user),'cheryl white'))
thissite = 'manly';
elseif ~isempty(strfind(lower(user),'jenny harley'))
thissite = 'manly';
end
end
%Update DB and move file
startcell = ['A' num2str(lastrow)];
imtype = 'Snap'; %Assume it is a snap
filename = files(i).name;
filename = strrep(filename,'jpeg','jpg'); %Change file extension to jpg
newdata = {thissite,user, datestr(time,'dd/mm/yyyy HH:MM'),timezone,filename,'Email',imtype,timequality};
xlswrite(dbfile,newdata,'database',startcell) %Write new line in spreadsheet
if strcmp(thissite,'unclassified')
movefile([EZdir filesep files(i).name],[image_path filesep thissite filesep filename],'f')
else
movefile([EZdir filesep files(i).name],[image_path filesep thissite filesep 'Raw' filesep filename],'f')
end
disp(['File moved to site ' thissite ' Raw directory'])
end