-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorMatch_exported.m
More file actions
322 lines (272 loc) · 13.1 KB
/
ColorMatch_exported.m
File metadata and controls
322 lines (272 loc) · 13.1 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
classdef ColorMatch_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
RedSliderLabel matlab.ui.control.Label
RedSlider matlab.ui.control.Slider
GreenSliderLabel matlab.ui.control.Label
GreenSlider matlab.ui.control.Slider
BlueSliderLabel matlab.ui.control.Label
BlueSlider matlab.ui.control.Slider
SubmitButton matlab.ui.control.Button
StartButton matlab.ui.control.Button
ScoreEditFieldLabel matlab.ui.control.Label
ScoreEditField matlab.ui.control.NumericEditField
CumulativeEditFieldLabel matlab.ui.control.Label
CumulativeEditField matlab.ui.control.NumericEditField
TrialEditFieldLabel matlab.ui.control.Label
TrialEditField matlab.ui.control.NumericEditField
RightPanel matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
UIAxes_2 matlab.ui.control.UIAxes
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
properties (Access = private)
init % Initial image
targ % Target image
ii = 1; % Counter
D % Score Record
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
msgbox('Welcome to ColorMatch. Press the START button, attempt to match the color on the top display as close as possible using the three sliders, then press SUBMIT. Aim for a score below 3 after 10 trials!')
end
% Changes arrangement of the app based on UIFigure width
function updateAppLayout(app, event)
currentFigureWidth = app.UIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2x1 grid
app.GridLayout.RowHeight = {480, 480};
app.GridLayout.ColumnWidth = {'1x'};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1x2 grid
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnWidth = {220, '1x'};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
end
% Button pushed function: SubmitButton
function SubmitButtonPushed(app, event)
% app.ScoreEditField.Value = {num2str(app.targ(1,1,1)) num2str(app.targ(1,1,2)) num2str(app.targ(1,1,3))};
A = [app.init(1,1,1) app.init(1,1,2) app.init(1,1,3)];
B = [app.targ(1,1,1) app.targ(1,1,2) app.targ(1,1,3)];
app.D(app.ii) = norm(im2double(B-A));
app.ScoreEditField.Value = app.D(app.ii);
app.TrialEditField.Value = app.ii;
app.ii = app.ii+1;
app.CumulativeEditField.Value = sum(app.D);
%app.init = ones(size(app.init,1),size(app.init,2),3,'uint8')
%app.init = uint8(255.*rand(size(app.init)));
app.init = uint8( ones(size(app.init)).*(255.*rand(1,1,3)) );
image(app.UIAxes,app.init)
end
% Button pushed function: StartButton
function StartButtonPushed(app, event)
% app.init = uint8( ones(size(app.init)).*(255.*rand(1,1,3)) );
app.init = zeros(app.UIAxes.Position(3),app.UIAxes.Position(4),3,'uint8');
app.init = uint8( ones(size(app.init)).*(255.*rand(1,1,3)) );
image(app.UIAxes,app.init)
app.targ = uint8( ones(size(app.init)).*(255.*rand(1,1,3)) );
image(app.UIAxes_2,app.targ)
end
% Value changed function: RedSlider
function RedSliderValueChanged(app, event)
% value = app.RedSlider.Value;
% app.targ(:,:,1) = value;
% image(app.UIAxes_2,app.targ)
%app.ScoreEditField.Value = {num2str(app.RedSlider.Value) num2str(app.GreenSlider.Value) num2str(app.BlueSlider.Value)};
end
% Value changed function: GreenSlider
function GreenSliderValueChanged(app, event)
%value = app.GreenSlider.Value;
%app.targ(:,:,2) = value;
%image(app.UIAxes_2,app.targ)
%app.ScoreEditField.Value = {num2str(app.RedSlider.Value) num2str(app.GreenSlider.Value) num2str(app.BlueSlider.Value)};
end
% Value changed function: BlueSlider
function BlueSliderValueChanged(app, event)
%value = app.BlueSlider.Value;
%app.targ(:,:,3) = value;
% image(app.UIAxes_2,app.targ)
% app.ScoreEditField.Value = {num2str(app.RedSlider.Value) num2str(app.GreenSlider.Value) num2str(app.BlueSlider.Value)};
end
% Value changing function: RedSlider
function RedSliderValueChanging(app, event)
changingValue = event.Value;
app.targ(:,:,1) = changingValue;
image(app.UIAxes_2,app.targ)
end
% Value changing function: GreenSlider
function GreenSliderValueChanging(app, event)
changingValue = event.Value;
app.targ(:,:,2) = changingValue;
image(app.UIAxes_2,app.targ)
end
% Value changing function: BlueSlider
function BlueSliderValueChanging(app, event)
changingValue = event.Value;
app.targ(:,:,3) = changingValue;
image(app.UIAxes_2,app.targ)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);
% Create GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {220, '1x'};
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable = 'on';
% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
% Create RedSliderLabel
app.RedSliderLabel = uilabel(app.LeftPanel);
app.RedSliderLabel.HorizontalAlignment = 'right';
app.RedSliderLabel.Position = [10 399 27 22];
app.RedSliderLabel.Text = 'Red';
% Create RedSlider
app.RedSlider = uislider(app.LeftPanel);
app.RedSlider.Limits = [0 255];
app.RedSlider.MajorTicks = [];
app.RedSlider.ValueChangedFcn = createCallbackFcn(app, @RedSliderValueChanged, true);
app.RedSlider.ValueChangingFcn = createCallbackFcn(app, @RedSliderValueChanging, true);
app.RedSlider.MinorTicks = [];
app.RedSlider.Position = [58 408 150 3];
% Create GreenSliderLabel
app.GreenSliderLabel = uilabel(app.LeftPanel);
app.GreenSliderLabel.HorizontalAlignment = 'right';
app.GreenSliderLabel.Position = [-1 345 38 22];
app.GreenSliderLabel.Text = 'Green';
% Create GreenSlider
app.GreenSlider = uislider(app.LeftPanel);
app.GreenSlider.Limits = [0 255];
app.GreenSlider.MajorTicks = [];
app.GreenSlider.ValueChangedFcn = createCallbackFcn(app, @GreenSliderValueChanged, true);
app.GreenSlider.ValueChangingFcn = createCallbackFcn(app, @GreenSliderValueChanging, true);
app.GreenSlider.MinorTicks = [];
app.GreenSlider.Position = [58 354 150 3];
% Create BlueSliderLabel
app.BlueSliderLabel = uilabel(app.LeftPanel);
app.BlueSliderLabel.HorizontalAlignment = 'right';
app.BlueSliderLabel.Position = [8 296 29 22];
app.BlueSliderLabel.Text = 'Blue';
% Create BlueSlider
app.BlueSlider = uislider(app.LeftPanel);
app.BlueSlider.Limits = [0 255];
app.BlueSlider.MajorTicks = [];
app.BlueSlider.ValueChangedFcn = createCallbackFcn(app, @BlueSliderValueChanged, true);
app.BlueSlider.ValueChangingFcn = createCallbackFcn(app, @BlueSliderValueChanging, true);
app.BlueSlider.MinorTicks = [];
app.BlueSlider.Position = [58 305 150 3];
% Create SubmitButton
app.SubmitButton = uibutton(app.LeftPanel, 'push');
app.SubmitButton.ButtonPushedFcn = createCallbackFcn(app, @SubmitButtonPushed, true);
app.SubmitButton.Position = [62 154 100 22];
app.SubmitButton.Text = 'Submit';
% Create StartButton
app.StartButton = uibutton(app.LeftPanel, 'push');
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.StartButton.Position = [62 219 100 22];
app.StartButton.Text = 'Start';
% Create ScoreEditFieldLabel
app.ScoreEditFieldLabel = uilabel(app.LeftPanel);
app.ScoreEditFieldLabel.HorizontalAlignment = 'right';
app.ScoreEditFieldLabel.Position = [45 95 37 22];
app.ScoreEditFieldLabel.Text = 'Score';
% Create ScoreEditField
app.ScoreEditField = uieditfield(app.LeftPanel, 'numeric');
app.ScoreEditField.HorizontalAlignment = 'center';
app.ScoreEditField.Position = [97 95 65 22];
% Create CumulativeEditFieldLabel
app.CumulativeEditFieldLabel = uilabel(app.LeftPanel);
app.CumulativeEditFieldLabel.HorizontalAlignment = 'right';
app.CumulativeEditFieldLabel.Position = [16 52 66 22];
app.CumulativeEditFieldLabel.Text = 'Cumulative';
% Create CumulativeEditField
app.CumulativeEditField = uieditfield(app.LeftPanel, 'numeric');
app.CumulativeEditField.HorizontalAlignment = 'center';
app.CumulativeEditField.Position = [97 52 65 22];
% Create TrialEditFieldLabel
app.TrialEditFieldLabel = uilabel(app.LeftPanel);
app.TrialEditFieldLabel.HorizontalAlignment = 'right';
app.TrialEditFieldLabel.Position = [45 14 37 22];
app.TrialEditFieldLabel.Text = 'Trial #';
% Create TrialEditField
app.TrialEditField = uieditfield(app.LeftPanel, 'numeric');
app.TrialEditField.HorizontalAlignment = 'center';
app.TrialEditField.Position = [97 14 65 22];
% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
% Create UIAxes
app.UIAxes = uiaxes(app.RightPanel);
title(app.UIAxes, '')
xlabel(app.UIAxes, '')
ylabel(app.UIAxes, '')
app.UIAxes.PlotBoxAspectRatio = [1.65714285714286 1 1];
app.UIAxes.TickLength = [0 0];
app.UIAxes.XColor = 'none';
app.UIAxes.XTick = [];
app.UIAxes.YColor = 'none';
app.UIAxes.YTick = [];
app.UIAxes.Position = [60 264 300 185];
% Create UIAxes_2
app.UIAxes_2 = uiaxes(app.RightPanel);
title(app.UIAxes_2, '')
xlabel(app.UIAxes_2, '')
ylabel(app.UIAxes_2, '')
app.UIAxes_2.PlotBoxAspectRatio = [1.65714285714286 1 1];
app.UIAxes_2.TickLength = [0 0];
app.UIAxes_2.XColor = 'none';
app.UIAxes_2.XTick = [];
app.UIAxes_2.YColor = 'none';
app.UIAxes_2.YTick = [];
app.UIAxes_2.Position = [60 35 300 185];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = ColorMatch_exported
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end