-
Notifications
You must be signed in to change notification settings - Fork 12
/
brush_color.m
134 lines (115 loc) · 4.68 KB
/
brush_color.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function [yell,zFD,zID,bFlag] = brush_color(hFig,cc,zFD,zID,colorTab,t)
% brush_color.m
% Get brushed data from figure and based on specified color code modify data
% Inputs
% hFig - Figure handle
%
% cc - Keyboard shortcut label
% A string with a keyboard shortcut to label data as:
% 'r' - False detection
% 'y' - Highlight selected data to show features (shown in black)
% 'g' - True detection
% 'u' - Update data according to current color brush selection. The
% other keyboard shortcuts do not work if brush color is:
% red - False detection
% yellow - Highlight selected data to show features (shown in black)
% green - True detection
%
% zFD - An [N x 1] vector of detection times labeled as false detections,
% where N is the number of detections.
%
% zID - An [N x 2] matrix of detection labeled as ID detections, where
% 1st column contains the detection times and 2nd column an ID
% number associated with the colorTab
%
% colorTab - Color code for classification - ID signal types
% [191, 191, 0] type 1 green
% [191, 0, 191] type 2 purple
% [ 0, 127, 0] type 3 dark-green
% [ 0, 191, 191] type 4 light-blue
% [ 20, 43, 140] type 5 dark-blue
% [218, 179, 255] type 6 pale-purple
% [255, 214, 0] type 7 yellow
% [222, 125, 0] type 8 orange
% [255, 153, 199] type 9 pink
% [153, 51, 0] type 10 brown
%
% t - An [N x 1] vector of detection times from current window session.
%
%
%
% Output:
%
% yell - An [N x 1] vector of indices of highlighted detection times,
% where N is the number of detections.
%
% zFD - An [N x 1] vector of detection times labeled as false detections,
% where N is the number of detections.
%
% zID - An [N x 2] matrix of detection labeled as ID detections, where
% 1st column contains the detection times and 2nd column an ID
% number associated with the colorTab
%
% bFlag - Logical,track if brush is on record
yell = [];
% Find brushed axes
[brushDate, brushColor, bFlag] = get_brushed(hFig);
if ~isempty(brushDate)
if isequal(brushColor,[1,0,0]) || strcmp(cc,'r')
% Red paintbrush or 'r' = False Detections
disp(['Number of False Detections = ',num2str(length(brushDate))])
% Add false detections to FD matrix
[newFD,~] = intersect(t, brushDate);
zFD = [zFD; newFD];
% Clear brushed set from ID set (if exist ID)
if ~isempty(zID)
[~,zIDkeep] = setdiff(zID(:,1),zFD);
zID = zID(zIDkeep,:);
end
elseif isequal(brushColor,[0,1,0]) || strcmp(cc,'g')
% Green paintbrush or 'g' = True Detections
disp(['Number of Detections Selected = ',num2str(length(brushDate))])
if exist('zFD','var')
% Make sure you're not flagging something outside this session
[newTD,~] = intersect(t, brushDate);
[zFD,iC] = setdiff(zFD,newTD);
% Clear brushed set from ID set
if ~isempty(zID)
[~,zIDkeep] = setdiff(zID(:,1),newTD);
zID = zID(zIDkeep,:);
end
% Clear brushed set from FD set
if ~isempty(zFD)
[~,zFDkeep] = setdiff(zFD(:,1),newTD);
zFD = zFD(zFDkeep,:);
end
disp(['Remaining Number of False Detections = ',num2str(length(iC))])
end
elseif isequal(brushColor,[1,1,0]) || strcmp(cc,'y')
% Yellow paintbrush or 'y' = Highlight Detections
disp(['Start time selected data: ',datestr(brushDate(1),'dd-mm-yyyy HH:MM:SS.FFF')]);
[~,yell] = intersect(t, brushDate);
else
% Find color code to assign ID signal type
tfCompare = find(sum(bsxfun(@eq,colorTab,brushColor),2)==3);
if ~isempty(tfCompare)
specID = tfCompare;
% Write to ID file
disp(['Number of ID Detections = ',num2str(length(brushDate))])
[newIDtimes,~] = intersect(t, brushDate);
% check if already brushed
if ~isempty(zID)
[~,oldIDtimes] = intersect(zID(:,1), newIDtimes);
if ~isempty(oldIDtimes)
% remove any old labels for these times
zID(oldIDtimes, :) = [];
end
end
spLabels = ones(size(newIDtimes)).*specID;
newID = [newIDtimes,spLabels];
zID = [zID;newID];
else
bFlag = 0;
end
end
end