1 | function Out = aedes_rotateflip(DATA,squareImages) |
---|
2 | % AEDES_ROTATEFLIP - GUI for rotating and flipping files |
---|
3 | % |
---|
4 | % |
---|
5 | % Synopsis: |
---|
6 | % |
---|
7 | % Description: |
---|
8 | % |
---|
9 | % Examples: |
---|
10 | % |
---|
11 | % See also: |
---|
12 | % |
---|
13 | |
---|
14 | % This function is a part of Aedes - A graphical tool for analyzing |
---|
15 | % medical images |
---|
16 | % |
---|
17 | % Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi> |
---|
18 | % |
---|
19 | % Department of Physics, Department of Neurobiology |
---|
20 | % University of Kuopio, FINLAND |
---|
21 | % |
---|
22 | % This program may be used under the terms of the GNU General Public |
---|
23 | % License version 2.0 as published by the Free Software Foundation |
---|
24 | % and appearing in the file LICENSE.TXT included in the packaging of |
---|
25 | % this program. |
---|
26 | % |
---|
27 | % This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
---|
28 | % WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
29 | |
---|
30 | |
---|
31 | % Public variables |
---|
32 | H = []; |
---|
33 | Out = []; |
---|
34 | Dat = []; |
---|
35 | cancel = true; |
---|
36 | |
---|
37 | % Get file names and paths |
---|
38 | for ii=1:length(DATA) |
---|
39 | Dat.fnames{ii} = DATA{ii}.HDR.fname; |
---|
40 | Dat.fpaths{ii} = DATA{ii}.HDR.fpath; |
---|
41 | Dat.fullfiles{ii} = [DATA{ii}.HDR.fpath,... |
---|
42 | DATA{ii}.HDR.fname]; |
---|
43 | end |
---|
44 | H = l_DrawGUI; |
---|
45 | |
---|
46 | % Wait for quit |
---|
47 | waitfor(H.FH) |
---|
48 | if cancel |
---|
49 | clear H Dat cancel |
---|
50 | return |
---|
51 | end |
---|
52 | |
---|
53 | function H=l_DrawGUI() |
---|
54 | |
---|
55 | %% Load default font and colors |
---|
56 | %FigColor=get(0,'DefaultUicontrolBackgroundcolor'); |
---|
57 | GD=aedes_gui_defaults; |
---|
58 | %GD.col.mainfig = FigColor; |
---|
59 | fig_h = 305; |
---|
60 | fig_w = 500; |
---|
61 | fig_location = aedes_dialoglocation([fig_w,fig_h]); |
---|
62 | fig_pos = [fig_location(1) fig_location(2) fig_w fig_h]; |
---|
63 | |
---|
64 | %% The main figure |
---|
65 | H.FH = figure('position',fig_pos,... |
---|
66 | 'Units','Pixel', ... |
---|
67 | 'Name','Rotate/Flip images', ... |
---|
68 | 'Numbertitle','off', ... |
---|
69 | 'Tag','im_rotate_gui', ... |
---|
70 | 'Color',GD.col.mainfig, ... |
---|
71 | 'Toolbar','none', ... |
---|
72 | 'Menubar','none', ... |
---|
73 | 'DoubleBuffer','on', ... |
---|
74 | 'DockControls','off',... |
---|
75 | 'renderer','painters',... |
---|
76 | 'KeyPressFcn','',... |
---|
77 | 'resize','off',... |
---|
78 | 'windowstyle','modal'); |
---|
79 | |
---|
80 | % Options uipanel |
---|
81 | H.OPTUIPANEL = uipanel('parent',H.FH,... |
---|
82 | 'units','pixel',... |
---|
83 | 'backgroundcolor',GD.col.mainfig, ... |
---|
84 | 'position',[5 40 fig_w-10 fig_h-45]); |
---|
85 | |
---|
86 | % Rotation uipanel |
---|
87 | H.ROTUIGRP = uibuttongroup('parent',H.OPTUIPANEL,... |
---|
88 | 'units','pixel',... |
---|
89 | 'position',[10 135 110 105],... |
---|
90 | 'title','Rotation (CCW)',... |
---|
91 | 'backgroundcolor',GD.col.mainfig, ... |
---|
92 | 'SelectionChangeFcn',@l_SelectionChanged); |
---|
93 | |
---|
94 | % Rotation Radio buttons |
---|
95 | H.ROTNONE=uicontrol('parent',H.ROTUIGRP,... |
---|
96 | 'units','pixel',... |
---|
97 | 'style','radio',... |
---|
98 | 'position',[20 70 80 15],... |
---|
99 | 'backgroundcolor',GD.col.mainfig, ... |
---|
100 | 'string','none',... |
---|
101 | 'value',1); |
---|
102 | tmp=get(H.ROTNONE,'position'); |
---|
103 | H.ROT90=uicontrol('parent',H.ROTUIGRP,... |
---|
104 | 'units','pixel',... |
---|
105 | 'style','radio',... |
---|
106 | 'position',[tmp(1) tmp(2)-20 tmp(3) tmp(4)],... |
---|
107 | 'string',['90',char(186)],... |
---|
108 | 'backgroundcolor',GD.col.mainfig, ... |
---|
109 | 'value',0); |
---|
110 | tmp=get(H.ROT90,'position'); |
---|
111 | H.ROT180=uicontrol('parent',H.ROTUIGRP,... |
---|
112 | 'units','pixel',... |
---|
113 | 'style','radio',... |
---|
114 | 'position',[tmp(1) tmp(2)-20 tmp(3) tmp(4)],... |
---|
115 | 'string',['180',char(186)],... |
---|
116 | 'backgroundcolor',GD.col.mainfig, ... |
---|
117 | 'value',0); |
---|
118 | tmp=get(H.ROT180,'position'); |
---|
119 | H.ROT270=uicontrol('parent',H.ROTUIGRP,... |
---|
120 | 'units','pixel',... |
---|
121 | 'style','radio',... |
---|
122 | 'position',[tmp(1) tmp(2)-20 tmp(3) tmp(4)],... |
---|
123 | 'string',['270',char(186)],... |
---|
124 | 'backgroundcolor',GD.col.mainfig, ... |
---|
125 | 'value',0); |
---|
126 | if ~squareImages |
---|
127 | set([H.ROT90,H.ROT270],'enable','off') |
---|
128 | end |
---|
129 | |
---|
130 | % Flip uipanel |
---|
131 | tmp = get(H.ROTUIGRP,'position'); |
---|
132 | H.FLIPUIGRP = uibuttongroup('parent',H.OPTUIPANEL,... |
---|
133 | 'units','pixel',... |
---|
134 | 'position',[tmp(1) tmp(2)-85-15 tmp(3) 85],... |
---|
135 | 'title','Flipping',... |
---|
136 | 'backgroundcolor',GD.col.mainfig, ... |
---|
137 | 'SelectionChangeFcn',@l_SelectionChanged); |
---|
138 | |
---|
139 | % Flipping radio buttons |
---|
140 | H.FLIPNONE=uicontrol('parent',H.FLIPUIGRP,... |
---|
141 | 'units','pixel',... |
---|
142 | 'style','radio',... |
---|
143 | 'position',[20 50 80 15],... |
---|
144 | 'backgroundcolor',GD.col.mainfig, ... |
---|
145 | 'string','none',... |
---|
146 | 'value',1); |
---|
147 | tmp=get(H.FLIPNONE,'position'); |
---|
148 | H.FLIPUD=uicontrol('parent',H.FLIPUIGRP,... |
---|
149 | 'units','pixel',... |
---|
150 | 'style','radio',... |
---|
151 | 'position',[tmp(1) tmp(2)-20 tmp(3) tmp(4)],... |
---|
152 | 'string','Up/Down',... |
---|
153 | 'backgroundcolor',GD.col.mainfig, ... |
---|
154 | 'value',0); |
---|
155 | tmp=get(H.FLIPUD,'position'); |
---|
156 | H.FLIPLR=uicontrol('parent',H.FLIPUIGRP,... |
---|
157 | 'units','pixel',... |
---|
158 | 'style','radio',... |
---|
159 | 'position',[tmp(1) tmp(2)-20 tmp(3) tmp(4)],... |
---|
160 | 'string','Left/Right',... |
---|
161 | 'backgroundcolor',GD.col.mainfig, ... |
---|
162 | 'value',0); |
---|
163 | |
---|
164 | % File listbox |
---|
165 | tmp = get(H.FLIPUIGRP,'position'); |
---|
166 | H.FILELBOX = uicontrol('parent',H.OPTUIPANEL,... |
---|
167 | 'units','pixel',... |
---|
168 | 'style','listbox',... |
---|
169 | 'position',[tmp(1)+tmp(3)+10 tmp(2) fig_w-tmp(1)-tmp(3)-35 ... |
---|
170 | 200],... |
---|
171 | 'backgroundcolor','w',... |
---|
172 | 'string',Dat.fullfiles,... |
---|
173 | 'Min',0,'Max',2); |
---|
174 | tmp = get(H.FILELBOX,'position'); |
---|
175 | files_tx = uicontrol('parent',H.OPTUIPANEL,... |
---|
176 | 'units','pixel',... |
---|
177 | 'style','text',... |
---|
178 | 'position',[tmp(1) tmp(2)+tmp(4) 150 12],... |
---|
179 | 'string','Files (slices)',... |
---|
180 | 'horizontalalign','left',... |
---|
181 | 'backgroundcolor',GD.col.mainfig, ... |
---|
182 | 'fontweig','bold'); |
---|
183 | |
---|
184 | % Select all and select none buttons |
---|
185 | tmp = get(H.FILELBOX,'position'); |
---|
186 | H.SELALL = uicontrol('parent',H.OPTUIPANEL,... |
---|
187 | 'units','pixel',... |
---|
188 | 'style','pushbutton',... |
---|
189 | 'position',[tmp(1) tmp(2)-25-5 tmp(3)/2-5 25],... |
---|
190 | 'string','Select All',... |
---|
191 | 'callback',@l_SelectAll); |
---|
192 | tmp = get(H.SELALL,'position'); |
---|
193 | H.SELNONE = uicontrol('parent',H.OPTUIPANEL,... |
---|
194 | 'units','pixel',... |
---|
195 | 'style','pushbutton',... |
---|
196 | 'position',[tmp(1)+tmp(3)+10 tmp(2) tmp(3) 25],... |
---|
197 | 'string','Select None',... |
---|
198 | 'userdata',H.FILELBOX,... |
---|
199 | 'callback','set(get(gcbo,''userdata''),''value'',[])'); |
---|
200 | |
---|
201 | % OK button |
---|
202 | H.OKBTN = uicontrol('parent',H.FH,... |
---|
203 | 'units','pixel',... |
---|
204 | 'position',[350 5 70 30],... |
---|
205 | 'string','OK',... |
---|
206 | 'callback',@l_OKCallBack); |
---|
207 | |
---|
208 | % Cancel button |
---|
209 | tmp = get(H.OKBTN,'position'); |
---|
210 | H.CANCELTN = uicontrol('parent',H.FH,... |
---|
211 | 'units','pixel',... |
---|
212 | 'position',[tmp(1)+tmp(3)+5 tmp(2) tmp(3) tmp(4)],... |
---|
213 | 'string','Cancel',... |
---|
214 | 'callback','delete(gcbf)'); |
---|
215 | |
---|
216 | end % function l_DrawGUI() |
---|
217 | |
---|
218 | |
---|
219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
220 | % |
---|
221 | % Select All Files |
---|
222 | % |
---|
223 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
224 | function l_SelectAll(h,evd) |
---|
225 | lbox_length = length(get(H.FILELBOX,'string')); |
---|
226 | set(H.FILELBOX,'value',1:lbox_length); |
---|
227 | end % function l_SelectAll(h, |
---|
228 | |
---|
229 | |
---|
230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
231 | % |
---|
232 | % Selection Changed |
---|
233 | % |
---|
234 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
235 | function l_SelectionChanged(h,evd) |
---|
236 | |
---|
237 | if h==H.ROTUIGRP |
---|
238 | |
---|
239 | if evd.NewValue==H.ROTNONE |
---|
240 | set([H.FLIPNONE,H.FLIPUD,H.FLIPLR],'enable','on') |
---|
241 | else |
---|
242 | set([H.FLIPNONE,H.FLIPUD,H.FLIPLR],'enable','off') |
---|
243 | end |
---|
244 | |
---|
245 | elseif h==H.FLIPUIGRP |
---|
246 | |
---|
247 | if evd.NewValue==H.FLIPNONE |
---|
248 | if ~squareImages |
---|
249 | set([H.ROTNONE,H.ROT180],'enable','on') |
---|
250 | else |
---|
251 | set([H.ROTNONE,H.ROT90,H.ROT180,H.ROT270],'enable','on') |
---|
252 | end |
---|
253 | else |
---|
254 | set([H.ROTNONE,H.ROT90,H.ROT180,H.ROT270],'enable','off') |
---|
255 | end |
---|
256 | |
---|
257 | end |
---|
258 | |
---|
259 | end % function |
---|
260 | |
---|
261 | |
---|
262 | |
---|
263 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
264 | % |
---|
265 | % OK Selected |
---|
266 | % |
---|
267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
268 | function l_OKCallBack(h,evd) |
---|
269 | |
---|
270 | cancel = false; |
---|
271 | val = get(H.FILELBOX,'value'); |
---|
272 | str = get(H.FILELBOX,'string'); |
---|
273 | RotSelObject = get(H.ROTUIGRP,'SelectedObject'); |
---|
274 | FlipSelObject = get(H.FLIPUIGRP,'SelectedObject'); |
---|
275 | |
---|
276 | %% Flipping vector: |
---|
277 | %% 0 = none |
---|
278 | %% 1 = Up/Down |
---|
279 | %% 2 = Left/Right |
---|
280 | Out.Flip = zeros(1,length(str)); |
---|
281 | if ~isempty(val) |
---|
282 | if FlipSelObject==H.FLIPUD |
---|
283 | Out.Flip(val)=1; |
---|
284 | elseif FlipSelObject==H.FLIPLR |
---|
285 | Out.Flip(val)=2; |
---|
286 | end |
---|
287 | end |
---|
288 | |
---|
289 | %% Rotate vector |
---|
290 | %% 0 = none |
---|
291 | %% 1 = 90 |
---|
292 | %% 2 = 180 |
---|
293 | %% 3 = 270 |
---|
294 | Out.Rotate = zeros(1,length(str)); |
---|
295 | if ~isempty(val) |
---|
296 | if RotSelObject==H.ROT90 |
---|
297 | Out.Rotate(val)=1; |
---|
298 | elseif RotSelObject==H.ROT180 |
---|
299 | Out.Rotate(val)=2; |
---|
300 | elseif RotSelObject==H.ROT270 |
---|
301 | Out.Rotate(val)=3; |
---|
302 | end |
---|
303 | end |
---|
304 | |
---|
305 | %% Delete figure window |
---|
306 | delete(H.FH) |
---|
307 | |
---|
308 | end % function l_OKCallBack(h, |
---|
309 | |
---|
310 | end |
---|