-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathImageDisplayGui2D.m
149 lines (133 loc) · 4.47 KB
/
ImageDisplayGui2D.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
function ImageDisplayGui2D(image, h)
%ImageDisplayGui2D Auxiliary function for IR Tools
%
% This function implements a GUI with two radio buttons.
% Silvia Gazzola, University of Bath
% Per Christian Hansen, Technical University of Denmark
% James G. Nagy, Emory University
% April, 2018.
% This file is part of the IR Tools package and is distributed under the
% 3-Clause BSD Licence. A separate license file should be provided as part
% of the package.
if nargin == 1
h = [];
end
%
% Create a figure and axes for the GUI, and display image
%
if isempty(h)
h = figure('Visible','off');
else
figure(h), clf
end
imagesc(image), axis off, axis image, colormap(gray), colorbar
%
% Create pop-up menu for the color map of the display.
% Default will be hot.
%
%ColorMapPopup =
uicontrol('Style', 'popup',...
'String', {'gray','hot','jet','parula','hsv','cool'},...
'Position', [90 -10 80 50],...
'Callback', @SetColorMap_Callback);
%
% Create pop-up menu for the scale of the display.
% Default will be no scaling.
%
%ScalePopup =
uicontrol('Style', 'popup',...
'String', {'original scale','truncate negative pixels','square root scale','log scale'},...
'Position', [170 -10 160 50],...
'Callback', @Scale_Callback);
%
% Create pop-up menu to save image.
% Default will be hot.
%
%SavePopup =
uicontrol('Style', 'popup',...
'String', {'save as jpeg','save as eps','help'},...
'Position', [325 -10 160 50],...
'Callback', @Save_Callback);
%
% Make figure visble after adding all components.
% Note that R2014b allows dot notation for setting and getting, e.g.,
%
% FigureHandle.Visible = 'on';
%
% but earlier versions do not. Make sure this works for older releases.
%
set(h, 'Visible', 'on');
%
% Next we have all of the callback functions, which are implemented
% as nested functions (this means all of the above variables are
% accessible to the nested functions, without having to explicitly
% pass them).
%
c = colorbar;
c.FontSize = 16;
function SetColorMap_Callback(source,~)
%
% This call back function sets the color map for the image
% display.
%
val = get(source,'Value');
maps = get(source,'String');
%
% For R2014b and later, we could implment the above steps as:
% val = source.Value;
% maps = source.String;
%
newmap = maps{val};
colormap(newmap);
end
function Scale_Callback(source,~)
%
% This call back function sets the color map for the image
% display.
%
val = get(source,'Value');
switch val
case 1
imagesc(image), axis('image', 'off'), colorbar
case 2
imagesc(max(image, 0)), axis('image', 'off'), colorbar
case 3
imagesc(sqrt(max(image,0))), axis('image', 'off'), colorbar
case 4
imagesc(log(max(image,0))), axis('image', 'off'), colorbar
end
end
function Save_Callback(source,~)
%
% This call back function sets the color map for the image
% display.
%
val = get(source,'Value');
if ~isreal(h), h = h.Number; end
switch val
case 1
FileNameString = sprintf('Figure%d.jpg', h);
MessageString = sprintf('Saving file as ''Figure%d.jpg''',h);
fprintf(1,[MessageString,'\n']);
print('-noui',FileNameString,'-djpeg')
case 2
FileNameString = sprintf('Figure%d.eps', h);
MessageString = sprintf('Saving file as ''Figure%d.eps''',h);
fprintf(1,[MessageString,'\n']);
print('-noui',FileNameString,'-depsc')
case 3
MessageString1 = sprintf('If you want to turn off the colorbar, in the Command Window enter:');
MessageString2 = sprintf(' colorbar off');
MessageString3 = sprintf('If you want to save to other formats, or to a specified file name,');
MessageString4 = sprintf('in the Command Window, enter:');
MessageString5 = sprintf(' print(''-noui'',MyFileName,FormatFlag)');
MessageString6 = sprintf('See doc print for more help.');
fprintf(1,[MessageString1,'\n']);
fprintf(1,[MessageString2,'\n']);
fprintf(1,[MessageString3,'\n']);
fprintf(1,[MessageString4,'\n']);
fprintf(1,[MessageString5,'\n']);
fprintf(1,[MessageString6,'\n']);
end
end
end