This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgui.m
389 lines (311 loc) · 15 KB
/
gui.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
classdef gui < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
SourcePanel matlab.ui.container.Panel
Label matlab.ui.control.Label
BrowseSourceButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
UIAxes_2 matlab.ui.control.UIAxes
DropDown matlab.ui.control.DropDown
WatermarkPanel matlab.ui.container.Panel
BrowseWMButton matlab.ui.control.Button
Label_2 matlab.ui.control.Label
UIAxes_3 matlab.ui.control.UIAxes
UIAxes_4 matlab.ui.control.UIAxes
UIAxes_5 matlab.ui.control.UIAxes
DropDown_2 matlab.ui.control.DropDown
ResultsPanel matlab.ui.container.Panel
EmbedButton matlab.ui.control.Button
ExtractButton matlab.ui.control.Button
UIAxes_6 matlab.ui.control.UIAxes
UIAxes_7 matlab.ui.control.UIAxes
EditField matlab.ui.control.NumericEditField
EmbeddingStrengthLabel matlab.ui.control.Label
SaveButton matlab.ui.control.Button
Logic
end
methods (Access = private)
% Button pushed function: BrowseSourceButton
function BrowseSourceButtonPushed(app, ~)
% Allow only some image extensions for selection from dialog box
[file,path] = uigetfile({'*.jpg';'*.jpeg';'*.png';'*.tiff';'*.bmp';'*.tif'});
% If file is selected
if ~isequal(file,0)
if size(imread(fullfile(path,file)),3) == 3
app.DropDown.Enable = 'on';
else
app.DropDown.Value = 'Grayscale';
title(app.UIAxes_2, app.DropDown.Value);
app.DropDown.Enable = 'off';
end
app.UIFigure.Visible = 'off';
app.UIFigure.Visible = 'on';
% Get Component Type
type = app.DropDown.Value;
app.Logic.initializeSource(fullfile(path,file),type);
% Show filename in Label
set(app.Label,'Text',file);
% Display image in 1st Box
imshow(fullfile(path,file),'Parent',app.UIAxes);
% Display image in 2nd Box
imshow(app.Logic.SourceImage,'Parent',app.UIAxes_2);
% Enable EmbedButton and Strength Field if EmbedEnable is
% set
if app.Logic.EmbedEnable
app.EmbedButton.Enable = 'on';
app.EditField.Enable = 'on';
end
% Enable WMButton and it's component dropdown
app.BrowseWMButton.Enable = 'on';
app.DropDown_2.Enable = 'on';
end
end
% Button pushed function: BrowseWMButton
function BrowseWMButtonPushed(app, ~)
% Allow only some image extensions for selection from dialog box
[file,path] = uigetfile({'*.jpg';'*.jpeg';'*.png';'*.tiff';'*.bmp';'*.tif'});
% If file is selected
if ~isequal(file,0)
if size(imread(fullfile(path,file)),3) == 3
app.DropDown_2.Enable = 'on';
else
app.DropDown_2.Value = 'Grayscale';
title(app.UIAxes_4, app.DropDown_2.Value);
app.DropDown_2.Enable = 'off';
end
app.UIFigure.Visible = 'off';
app.UIFigure.Visible = 'on';
% Get Component Type
type = app.DropDown_2.Value;
alteredWM = app.Logic.initializeWM(fullfile(path,file),type);
% Show filename in Label2
set(app.Label_2,'Text',file);
% Display image in 3rd Box
imshow(fullfile(path,file),'Parent',app.UIAxes_3);
% Display image in 4th Box
imshow(alteredWM,'Parent',app.UIAxes_4);
% Display image in 5th Box
imshow(app.Logic.WMImage,'Parent',app.UIAxes_5);
% Enable EmbedButton and Strength Field if EmbedEnable is
% set
if app.Logic.EmbedEnable
app.EmbedButton.Enable = 'on';
app.EditField.Enable = 'on';
end
end
end
% Button pushed function: EmbedButton
function EmbedButtonPushed(app, ~)
% Get Embedding Strength from input
alpha = app.EditField.Value;
% Embed the watermark
app.Logic.embed(alpha);
% Display image in 6th Box
imshow(app.Logic.WatermarkedImage,'Parent',app.UIAxes_6);
title(app.UIAxes_6, ['Result: A=',num2str(alpha)])
% Enable ExtractButton
app.ExtractButton.Enable = 'on';
% Enable SaveButton
app.SaveButton.Enable = 'on';
end
% Button pushed function: ExtractButton
function ExtractButtonPushed(app, ~)
% Fetch ExtractedImage Object
ExtractedImage = app.Logic.extract();
% Display image in 7th Box
imshow(ExtractedImage,'Parent',app.UIAxes_7);
title(app.UIAxes_7, ['Extracted Image: A=',num2str(app.Logic.Alpha)])
end
% Button pushed function: SaveButton
function SaveButtonPushed(app, ~)
% Open Save Image dialog
[fn, ext, ucancel] = imputfile;
if ~isequal(ucancel,1)
imwrite(app.Logic.WatermarkedImage,fn,ext);
end
app.UIFigure.Visible = 'off';
app.UIFigure.Visible = 'on';
end
% Value changed function: DropDown
function DropDownValueChanged(app, ~)
% Change title
title(app.UIAxes_2, app.DropDown.Value);
% Re-evaluate image
if ~isempty(app.Logic.SourceFile)
app.Logic.initializeSource(app.Logic.SourceFile,app.DropDown.Value);
imshow(app.Logic.SourceImage,'Parent',app.UIAxes_2);
end
end
% Value changed function: DropDown_2
function DropDown_2ValueChanged(app, ~)
% Change title
title(app.UIAxes_4, app.DropDown_2.Value);
% Re-evaluate image
if ~isempty(app.Logic.WMFile)
alteredWM = app.Logic.initializeWM(app.Logic.WMFile,app.DropDown_2.Value);
imshow(alteredWM,'Parent',app.UIAxes_4);
imshow(app.Logic.WMImage,'Parent',app.UIAxes_5);
end
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Color = [0.5098 0.7451 1];
app.UIFigure.Position = [100 100 1123 744];
app.UIFigure.Name = 'DWT Watermarking';
% Create SourcePanel
app.SourcePanel = uipanel(app.UIFigure);
app.SourcePanel.Title = 'Source';
app.SourcePanel.BackgroundColor = [1 1 1];
app.SourcePanel.Position = [20 509 777 224];
% Create Label
app.Label = uilabel(app.SourcePanel);
app.Label.BackgroundColor = [0.8 0.8 0.8];
app.Label.Position = [20 91 100 26];
app.Label.Text = '';
% Create BrowseSourceButton
app.BrowseSourceButton = uibutton(app.SourcePanel, 'push');
app.BrowseSourceButton.BackgroundColor = [0 0.451 0.7412];
app.BrowseSourceButton.FontColor = [1 1 1];
app.BrowseSourceButton.Position = [20 135 100 29];
app.BrowseSourceButton.Text = 'Browse Source';
% Create UIAxes
app.UIAxes = uiaxes(app.SourcePanel);
title(app.UIAxes, 'Original Image')
app.UIAxes.Box = 'on';
app.UIAxes.Color = [0 0.451 0.7412];
app.UIAxes.Position = [139 12 300 185];
% Create DropDown
app.DropDown = uidropdown(app.SourcePanel);
app.DropDown.Items = {'Grayscale', 'R Component', 'G Component', 'B Component'};
app.DropDown.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
app.DropDown.Position = [21 45 100 22];
app.DropDown.Value = 'Grayscale';
% Create UIAxes_2
app.UIAxes_2 = uiaxes(app.SourcePanel);
title(app.UIAxes_2, app.DropDown.Value)
app.UIAxes_2.Box = 'on';
app.UIAxes_2.Color = [0 0.451 0.7412];
app.UIAxes_2.Position = [464 12 300 185];
% Create WatermarkPanel
app.WatermarkPanel = uipanel(app.UIFigure);
app.WatermarkPanel.Title = 'Watermark';
app.WatermarkPanel.Position = [20 269 1086 224];
% Create BrowseWMButton
app.BrowseWMButton = uibutton(app.WatermarkPanel, 'push');
app.BrowseWMButton.BackgroundColor = [0 0.451 0.7412];
app.BrowseWMButton.FontColor = [1 1 1];
app.BrowseWMButton.Enable = 'off';
app.BrowseWMButton.Position = [22 128 100 30];
app.BrowseWMButton.Text = 'Browse WM';
% Create Label_2
app.Label_2 = uilabel(app.WatermarkPanel);
app.Label_2.BackgroundColor = [0.8 0.8 0.8];
app.Label_2.Position = [22 84 100 26];
app.Label_2.Text = '';
% Create UIAxes_3
app.UIAxes_3 = uiaxes(app.WatermarkPanel);
title(app.UIAxes_3, 'Watermark')
app.UIAxes_3.Box = 'on';
app.UIAxes_3.Color = [0 0.451 0.7412];
app.UIAxes_3.Position = [139 9 300 185];
% Create UIAxes_5
app.UIAxes_5 = uiaxes(app.WatermarkPanel);
title(app.UIAxes_5, 'Resized')
app.UIAxes_5.Box = 'on';
app.UIAxes_5.Color = [0 0.451 0.7412];
app.UIAxes_5.Position = [776 9 300 185];
% Create DropDown_2
app.DropDown_2 = uidropdown(app.WatermarkPanel);
app.DropDown_2.Items = {'Grayscale', 'R Component', 'G Component', 'B Component'};
app.DropDown_2.ValueChangedFcn = createCallbackFcn(app, @DropDown_2ValueChanged, true);
app.DropDown_2.Position = [22 43 100 22];
app.DropDown_2.Value = 'Grayscale';
app.DropDown_2.Enable = 'off';
% Create UIAxes_4
app.UIAxes_4 = uiaxes(app.WatermarkPanel);
title(app.UIAxes_4, app.DropDown_2.Value)
app.UIAxes_4.Box = 'on';
app.UIAxes_4.Color = [0 0.451 0.7412];
app.UIAxes_4.Position = [464 9 300 185];
% Create ResultsPanel
app.ResultsPanel = uipanel(app.UIFigure);
app.ResultsPanel.Title = 'Results';
app.ResultsPanel.Position = [20 12 777 236];
% Create EmbedButton
app.EmbedButton = uibutton(app.ResultsPanel, 'push');
app.EmbedButton.BackgroundColor = [0 0.451 0.7412];
app.EmbedButton.FontColor = [1 1 1];
app.EmbedButton.Enable = 'off';
app.EmbedButton.Position = [20 109 100 30];
app.EmbedButton.Text = 'Embed';
% Create ExtractButton
app.ExtractButton = uibutton(app.ResultsPanel, 'push');
app.ExtractButton.BackgroundColor = [0 0.451 0.7412];
app.ExtractButton.FontColor = [1 1 1];
app.ExtractButton.Enable = 'off';
app.ExtractButton.Position = [20 21 100 30];
app.ExtractButton.Text = 'Extract';
% Create UIAxes_6
app.UIAxes_6 = uiaxes(app.ResultsPanel);
title(app.UIAxes_6, 'Result')
app.UIAxes_6.Box = 'on';
app.UIAxes_6.Color = [0 0.451 0.7412];
app.UIAxes_6.Position = [139 21 300 185];
% Create UIAxes_7
app.UIAxes_7 = uiaxes(app.ResultsPanel);
title(app.UIAxes_7, 'Extracted Watermark')
app.UIAxes_7.Box = 'on';
app.UIAxes_7.Color = [0 0.451 0.7412];
app.UIAxes_7.Position = [464 21 300 185];
% Create EditField
app.EditField = uieditfield(app.ResultsPanel, 'numeric');
app.EditField.Limits = [0 1];
app.EditField.ValueDisplayFormat = '%.2f';
app.EditField.Enable = 'off';
app.EditField.Position = [20 148 100 22];
app.EditField.Value = 0.75;
% Create EmbeddingStrengthLabel
app.EmbeddingStrengthLabel = uilabel(app.ResultsPanel);
app.EmbeddingStrengthLabel.Position = [13 180 117 15];
app.EmbeddingStrengthLabel.Text = 'Embedding Strength';
% Create SaveButton
app.SaveButton = uibutton(app.ResultsPanel, 'push');
app.SaveButton.BackgroundColor = [0 0.451 0.7412];
app.SaveButton.FontColor = [1 1 1];
app.SaveButton.Enable = 'off';
app.SaveButton.Position = [20 66 100 30];
app.SaveButton.Text = 'Save';
% Button Callbacks
app.BrowseSourceButton.ButtonPushedFcn = createCallbackFcn(app, @BrowseSourceButtonPushed, true);
app.BrowseWMButton.ButtonPushedFcn = createCallbackFcn(app, @BrowseWMButtonPushed, true);
app.EmbedButton.ButtonPushedFcn = createCallbackFcn(app, @EmbedButtonPushed, true);
app.ExtractButton.ButtonPushedFcn = createCallbackFcn(app, @ExtractButtonPushed, true);
app.SaveButton.ButtonPushedFcn = createCallbackFcn(app, @SaveButtonPushed, true);
end
end
methods (Access = public)
% Construct app
function app = gui
% Object of logic class
app.Logic = logic;
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
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