Home > coding_tools > object_annotation > label_roi > ROI_GUI.m

ROI_GUI

PURPOSE ^

ROI_GUI MATLAB code for ROI_GUI.fig

SYNOPSIS ^

function varargout = ROI_GUI(varargin)

DESCRIPTION ^

 ROI_GUI MATLAB code for ROI_GUI.fig
      ROI_GUI, by itself, creates a new ROI_GUI or raises the existing
      singleton*.

      H = ROI_GUI returns the handle to a new ROI_GUI or the handle to
      the existing singleton*.

      ROI_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
      function named CALLBACK in ROI_GUI.M with the given input arguments.

      ROI_GUI('Property','Value',...) creates a new ROI_GUI or raises the
      existing singleton*.  Starting from the left, property value pairs are
      applied to the GUI before ROI_GUI_OpeningFcn gets called.  An
      unrecognized property name or invalid value makes property application
      stop.  All inputs are passed to ROI_GUI_OpeningFcn via varargin.

      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
      instance to run (singleton)".

 See also: GUIDE, GUIDATA, GUIHANDLES

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = ROI_GUI(varargin)
0002 % ROI_GUI MATLAB code for ROI_GUI.fig
0003 %      ROI_GUI, by itself, creates a new ROI_GUI or raises the existing
0004 %      singleton*.
0005 %
0006 %      H = ROI_GUI returns the handle to a new ROI_GUI or the handle to
0007 %      the existing singleton*.
0008 %
0009 %      ROI_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
0010 %      function named CALLBACK in ROI_GUI.M with the given input arguments.
0011 %
0012 %      ROI_GUI('Property','Value',...) creates a new ROI_GUI or raises the
0013 %      existing singleton*.  Starting from the left, property value pairs are
0014 %      applied to the GUI before ROI_GUI_OpeningFcn gets called.  An
0015 %      unrecognized property name or invalid value makes property application
0016 %      stop.  All inputs are passed to ROI_GUI_OpeningFcn via varargin.
0017 %
0018 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0019 %      instance to run (singleton)".
0020 %
0021 % See also: GUIDE, GUIDATA, GUIHANDLES
0022 
0023 % Edit the above text to modify the response to help ROI_GUI
0024 
0025 % Last Modified by GUIDE v2.5 15-Oct-2015 13:45:49
0026 
0027 % Begin initialization code - DO NOT EDIT
0028 gui_Singleton = 1;
0029 gui_State = struct('gui_Name',       mfilename, ...
0030                    'gui_Singleton',  gui_Singleton, ...
0031                    'gui_OpeningFcn', @ROI_GUI_OpeningFcn, ...
0032                    'gui_OutputFcn',  @ROI_GUI_OutputFcn, ...
0033                    'gui_LayoutFcn',  [] , ...
0034                    'gui_Callback',   []);
0035 if nargin && ischar(varargin{1})
0036     gui_State.gui_Callback = str2func(varargin{1});
0037 end
0038 
0039 if nargout
0040     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0041 else
0042     gui_mainfcn(gui_State, varargin{:});
0043 end
0044 % End initialization code - DO NOT EDIT
0045 
0046 
0047 % --- Executes just before ROI_GUI is made visible.
0048 function ROI_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
0049 % This function has no output args, see OutputFcn.
0050 % hObject    handle to figure
0051 % eventdata  reserved - to be defined in a future version of MATLAB
0052 % handles    structure with handles and user data (see GUIDATA)
0053 % varargin   command line arguments to ROI_GUI (see VARARGIN)
0054 
0055 % Choose default command line output for ROI_GUI
0056 handles.output = hObject;
0057 
0058 % Update handles structure
0059 guidata(hObject, handles);
0060 
0061 % UIWAIT makes ROI_GUI wait for user response (see UIRESUME)
0062 % uiwait(handles.figure1);
0063 if length(varargin) > 0
0064     setappdata(handles.frame_1, 'CODER_NAME', varargin{1});
0065 else
0066     setappdata(handles.frame_1, 'CODER_NAME', '');
0067 end
0068 
0069 
0070 % --- Outputs from this function are returned to the command line.
0071 function varargout = ROI_GUI_OutputFcn(hObject, eventdata, handles) 
0072 % varargout  cell array for returning output args (see VARARGOUT);
0073 % hObject    handle to figure
0074 % eventdata  reserved - to be defined in a future version of MATLAB
0075 % handles    structure with handles and user data (see GUIDATA)
0076 
0077 % Get default command line output from handles structure
0078 varargout{1} = handles.output;
0079 
0080 % SET GUI VARIABLES
0081 setappdata(handles.frame_1, 'SAFE_MODE', 0);
0082 
0083 % turn off ugly figure axis
0084 set(handles.frame_1,'xcolor',get(gcf,'color'));
0085 set(handles.frame_1,'ycolor',get(gcf,'color'));
0086 set(handles.frame_1,'ytick',[]);
0087 set(handles.frame_1,'xtick',[]);
0088 set(handles.frame_2,'xcolor',get(gcf,'color'));
0089 set(handles.frame_2,'ycolor',get(gcf,'color'));
0090 set(handles.frame_2,'ytick',[]);
0091 set(handles.frame_2,'xtick',[]);
0092 set(handles.frame_3,'xcolor',get(gcf,'color'));
0093 set(handles.frame_3,'ycolor',get(gcf,'color'));
0094 set(handles.frame_3,'ytick',[]);
0095 set(handles.frame_3,'xtick',[]);
0096 set(handles.frame_4,'xcolor',get(gcf,'color'));
0097 set(handles.frame_4,'ycolor',get(gcf,'color'));
0098 set(handles.frame_4,'ytick',[]);
0099 set(handles.frame_4,'xtick',[]);
0100 
0101 set(handles.edit_frame_number, 'Enable', 'off');
0102 
0103 % create toy thumbnail imags
0104 thumbnails = cell(26, 1);
0105 for i = 1:length(thumbnails)-2
0106     thumbnails{i} = imread(['toys/' num2str(i) '.jpg']);
0107 end
0108 thumbnails{25} = imread(['toys/none.jpg']);
0109 thumbnails{26} = imread(['toys/face.jpg']);
0110 thumbnails{27} = imread(['toys/other.jpg']);
0111 imshow(thumbnails{1}, 'Parent', handles.img_1);
0112 imshow(thumbnails{2}, 'Parent', handles.img_2);
0113 imshow(thumbnails{3}, 'Parent', handles.img_3);
0114 imshow(thumbnails{4}, 'Parent', handles.img_4);
0115 imshow(thumbnails{5}, 'Parent', handles.img_5);
0116 imshow(thumbnails{6}, 'Parent', handles.img_6);
0117 imshow(thumbnails{7}, 'Parent', handles.img_7);
0118 imshow(thumbnails{8}, 'Parent', handles.img_8);
0119 imshow(thumbnails{9}, 'Parent', handles.img_9);
0120 imshow(thumbnails{10}, 'Parent', handles.img_10);
0121 imshow(thumbnails{11}, 'Parent', handles.img_11);
0122 imshow(thumbnails{12}, 'Parent', handles.img_12);
0123 imshow(thumbnails{13}, 'Parent', handles.img_13);
0124 imshow(thumbnails{14}, 'Parent', handles.img_14);
0125 imshow(thumbnails{15}, 'Parent', handles.img_15);
0126 imshow(thumbnails{16}, 'Parent', handles.img_16);
0127 imshow(thumbnails{17}, 'Parent', handles.img_17);
0128 imshow(thumbnails{18}, 'Parent', handles.img_18);
0129 imshow(thumbnails{19}, 'Parent', handles.img_19);
0130 imshow(thumbnails{20}, 'Parent', handles.img_20);
0131 imshow(thumbnails{21}, 'Parent', handles.img_21);
0132 imshow(thumbnails{22}, 'Parent', handles.img_22);
0133 imshow(thumbnails{23}, 'Parent', handles.img_23);
0134 imshow(thumbnails{24}, 'Parent', handles.img_24);
0135 imshow(thumbnails{25}, 'Parent', handles.img_none);
0136 imshow(thumbnails{26}, 'Parent', handles.img_face);
0137 imshow(thumbnails{27}, 'Parent', handles.img_other);
0138 
0139 
0140 % --- Executes on button press in pushbutton1.
0141 function button_none_Callback(hObject, eventdata, handles)
0142 % hObject    handle to pushbutton1 (see GCBO)
0143 % eventdata  reserved - to be defined in a future version of MATLAB
0144 % handles    structure with handles and user data (see GUIDATA)
0145 resetButtonColors(handles);
0146 set(handles.button_none, 'BackgroundColor','green');
0147 setappdata(handles.frame_1, 'ROI', 0);
0148 update_ROI_DATA(handles);
0149 
0150 % --- Executes on button press in button_1.
0151 function button_1_Callback(hObject, eventdata, handles)
0152 % hObject    handle to button_1 (see GCBO)
0153 % eventdata  reserved - to be defined in a future version of MATLAB
0154 % handles    structure with handles and user data (see GUIDATA)
0155 resetButtonColors(handles);
0156 set(handles.button_1, 'BackgroundColor','green');
0157 setappdata(handles.frame_1, 'ROI', 1);
0158 update_ROI_DATA(handles);
0159 
0160 % --- Executes on button press in button_2.
0161 function button_2_Callback(hObject, eventdata, handles)
0162 % hObject    handle to button_2 (see GCBO)
0163 % eventdata  reserved - to be defined in a future version of MATLAB
0164 % handles    structure with handles and user data (see GUIDATA)
0165 resetButtonColors(handles);
0166 set(handles.button_2, 'BackgroundColor','green');
0167 setappdata(handles.frame_1, 'ROI', 2);
0168 update_ROI_DATA(handles);
0169 
0170 % --- Executes on button press in button_3.
0171 function button_3_Callback(hObject, eventdata, handles)
0172 % hObject    handle to button_3 (see GCBO)
0173 % eventdata  reserved - to be defined in a future version of MATLAB
0174 % handles    structure with handles and user data (see GUIDATA)
0175 resetButtonColors(handles);
0176 set(handles.button_3, 'BackgroundColor','green');
0177 setappdata(handles.frame_1, 'ROI', 3);
0178 update_ROI_DATA(handles);
0179 
0180 % --- Executes on button press in button_4.
0181 function button_4_Callback(hObject, eventdata, handles)
0182 % hObject    handle to button_4 (see GCBO)
0183 % eventdata  reserved - to be defined in a future version of MATLAB
0184 % handles    structure with handles and user data (see GUIDATA)
0185 resetButtonColors(handles);
0186 set(handles.button_4, 'BackgroundColor','green');
0187 setappdata(handles.frame_1, 'ROI', 4);
0188 update_ROI_DATA(handles);
0189 
0190 % --- Executes on button press in button_5.
0191 function button_5_Callback(hObject, eventdata, handles)
0192 % hObject    handle to button_5 (see GCBO)
0193 % eventdata  reserved - to be defined in a future version of MATLAB
0194 % handles    structure with handles and user data (see GUIDATA)
0195 resetButtonColors(handles);
0196 set(handles.button_5, 'BackgroundColor','green');
0197 setappdata(handles.frame_1, 'ROI', 5);
0198 update_ROI_DATA(handles);
0199 
0200 % --- Executes on button press in button_6.
0201 function button_6_Callback(hObject, eventdata, handles)
0202 % hObject    handle to button_6 (see GCBO)
0203 % eventdata  reserved - to be defined in a future version of MATLAB
0204 % handles    structure with handles and user data (see GUIDATA)
0205 resetButtonColors(handles);
0206 set(handles.button_6, 'BackgroundColor','green');
0207 setappdata(handles.frame_1, 'ROI', 6);
0208 update_ROI_DATA(handles);
0209 
0210 % --- Executes on button press in button_7.
0211 function button_7_Callback(hObject, eventdata, handles)
0212 % hObject    handle to button_7 (see GCBO)
0213 % eventdata  reserved - to be defined in a future version of MATLAB
0214 % handles    structure with handles and user data (see GUIDATA)
0215 resetButtonColors(handles);
0216 set(handles.button_7, 'BackgroundColor','green');
0217 setappdata(handles.frame_1, 'ROI', 7);
0218 update_ROI_DATA(handles);
0219 
0220 % --- Executes on button press in button_8.
0221 function button_8_Callback(hObject, eventdata, handles)
0222 % hObject    handle to button_8 (see GCBO)
0223 % eventdata  reserved - to be defined in a future version of MATLAB
0224 % handles    structure with handles and user data (see GUIDATA)
0225 resetButtonColors(handles);
0226 set(handles.button_8, 'BackgroundColor','green');
0227 setappdata(handles.frame_1, 'ROI', 8);
0228 update_ROI_DATA(handles);
0229 
0230 % --- Executes on button press in button_9.
0231 function button_9_Callback(hObject, eventdata, handles)
0232 % hObject    handle to button_9 (see GCBO)
0233 % eventdata  reserved - to be defined in a future version of MATLAB
0234 % handles    structure with handles and user data (see GUIDATA)
0235 resetButtonColors(handles);
0236 set(handles.button_9, 'BackgroundColor','green');
0237 setappdata(handles.frame_1, 'ROI', 9);
0238 update_ROI_DATA(handles);
0239 
0240 % --- Executes on button press in button_10.
0241 function button_10_Callback(hObject, eventdata, handles)
0242 % hObject    handle to button_10 (see GCBO)
0243 % eventdata  reserved - to be defined in a future version of MATLAB
0244 % handles    structure with handles and user data (see GUIDATA)
0245 resetButtonColors(handles);
0246 set(handles.button_10, 'BackgroundColor','green');
0247 setappdata(handles.frame_1, 'ROI', 10);
0248 update_ROI_DATA(handles);
0249 
0250 % --- Executes on button press in button_11.
0251 function button_11_Callback(hObject, eventdata, handles)
0252 % hObject    handle to button_11 (see GCBO)
0253 % eventdata  reserved - to be defined in a future version of MATLAB
0254 % handles    structure with handles and user data (see GUIDATA)
0255 resetButtonColors(handles);
0256 set(handles.button_11, 'BackgroundColor','green');
0257 setappdata(handles.frame_1, 'ROI', 11);
0258 update_ROI_DATA(handles);
0259 
0260 % --- Executes on button press in button_12.
0261 function button_12_Callback(hObject, eventdata, handles)
0262 % hObject    handle to button_12 (see GCBO)
0263 % eventdata  reserved - to be defined in a future version of MATLAB
0264 % handles    structure with handles and user data (see GUIDATA)
0265 resetButtonColors(handles);
0266 set(handles.button_12, 'BackgroundColor','green');
0267 setappdata(handles.frame_1, 'ROI', 12);
0268 update_ROI_DATA(handles);
0269 
0270 % --- Executes on button press in button_face.
0271 function button_face_Callback(hObject, eventdata, handles)
0272 % hObject    handle to button_face (see GCBO)
0273 % eventdata  reserved - to be defined in a future version of MATLAB
0274 % handles    structure with handles and user data (see GUIDATA)
0275 resetButtonColors(handles);
0276 set(handles.button_face, 'BackgroundColor','green');
0277 setappdata(handles.frame_1, 'ROI', 25);
0278 update_ROI_DATA(handles);
0279 
0280 % --- Executes on button press in button_13.
0281 function button_13_Callback(hObject, eventdata, handles)
0282 % hObject    handle to button_13 (see GCBO)
0283 % eventdata  reserved - to be defined in a future version of MATLAB
0284 % handles    structure with handles and user data (see GUIDATA)
0285 resetButtonColors(handles);
0286 set(handles.button_13, 'BackgroundColor','green');
0287 setappdata(handles.frame_1, 'ROI', 13);
0288 update_ROI_DATA(handles);
0289 
0290 % --- Executes on button press in button_14.
0291 function button_14_Callback(hObject, eventdata, handles)
0292 % hObject    handle to button_14 (see GCBO)
0293 % eventdata  reserved - to be defined in a future version of MATLAB
0294 % handles    structure with handles and user data (see GUIDATA)
0295 resetButtonColors(handles);
0296 set(handles.button_14, 'BackgroundColor','green');
0297 setappdata(handles.frame_1, 'ROI', 14);
0298 update_ROI_DATA(handles);
0299 
0300 
0301 % --- Executes on button press in button_15.
0302 function button_15_Callback(hObject, eventdata, handles)
0303 % hObject    handle to button_15 (see GCBO)
0304 % eventdata  reserved - to be defined in a future version of MATLAB
0305 % handles    structure with handles and user data (see GUIDATA)
0306 resetButtonColors(handles);
0307 set(handles.button_15, 'BackgroundColor','green');
0308 setappdata(handles.frame_1, 'ROI', 15);
0309 update_ROI_DATA(handles);
0310 
0311 % --- Executes on button press in button_16.
0312 function button_16_Callback(hObject, eventdata, handles)
0313 % hObject    handle to button_16 (see GCBO)
0314 % eventdata  reserved - to be defined in a future version of MATLAB
0315 % handles    structure with handles and user data (see GUIDATA)
0316 resetButtonColors(handles);
0317 set(handles.button_16, 'BackgroundColor','green');
0318 setappdata(handles.frame_1, 'ROI', 16);
0319 update_ROI_DATA(handles);
0320 
0321 % --- Executes on button press in button_17.
0322 function button_17_Callback(hObject, eventdata, handles)
0323 % hObject    handle to button_17 (see GCBO)
0324 % eventdata  reserved - to be defined in a future version of MATLAB
0325 % handles    structure with handles and user data (see GUIDATA)
0326 resetButtonColors(handles);
0327 set(handles.button_17, 'BackgroundColor','green');
0328 setappdata(handles.frame_1, 'ROI', 17);
0329 update_ROI_DATA(handles);
0330 
0331 % --- Executes on button press in button_18.
0332 function button_18_Callback(hObject, eventdata, handles)
0333 % hObject    handle to button_18 (see GCBO)
0334 % eventdata  reserved - to be defined in a future version of MATLAB
0335 % handles    structure with handles and user data (see GUIDATA)
0336 resetButtonColors(handles);
0337 set(handles.button_18, 'BackgroundColor','green');
0338 setappdata(handles.frame_1, 'ROI', 18);
0339 update_ROI_DATA(handles);
0340 
0341 % --- Executes on button press in button_19.
0342 function button_19_Callback(hObject, eventdata, handles)
0343 % hObject    handle to button_19 (see GCBO)
0344 % eventdata  reserved - to be defined in a future version of MATLAB
0345 % handles    structure with handles and user data (see GUIDATA)
0346 resetButtonColors(handles);
0347 set(handles.button_19, 'BackgroundColor','green');
0348 setappdata(handles.frame_1, 'ROI', 19);
0349 update_ROI_DATA(handles);
0350 
0351 % --- Executes on button press in button_20.
0352 function button_20_Callback(hObject, eventdata, handles)
0353 % hObject    handle to button_20 (see GCBO)
0354 % eventdata  reserved - to be defined in a future version of MATLAB
0355 % handles    structure with handles and user data (see GUIDATA)
0356 resetButtonColors(handles);
0357 set(handles.button_20, 'BackgroundColor','green');
0358 setappdata(handles.frame_1, 'ROI', 20);
0359 update_ROI_DATA(handles);
0360 
0361 % --- Executes on button press in button_21.
0362 function button_21_Callback(hObject, eventdata, handles)
0363 % hObject    handle to button_21 (see GCBO)
0364 % eventdata  reserved - to be defined in a future version of MATLAB
0365 % handles    structure with handles and user data (see GUIDATA)
0366 resetButtonColors(handles);
0367 set(handles.button_21, 'BackgroundColor','green');
0368 setappdata(handles.frame_1, 'ROI', 21);
0369 update_ROI_DATA(handles);
0370 
0371 % --- Executes on button press in button_22.
0372 function button_22_Callback(hObject, eventdata, handles)
0373 % hObject    handle to button_22 (see GCBO)
0374 % eventdata  reserved - to be defined in a future version of MATLAB
0375 % handles    structure with handles and user data (see GUIDATA)
0376 resetButtonColors(handles);
0377 set(handles.button_22, 'BackgroundColor','green');
0378 setappdata(handles.frame_1, 'ROI', 22);
0379 update_ROI_DATA(handles);
0380 
0381 % --- Executes on button press in button_23.
0382 function button_23_Callback(hObject, eventdata, handles)
0383 % hObject    handle to button_23 (see GCBO)
0384 % eventdata  reserved - to be defined in a future version of MATLAB
0385 % handles    structure with handles and user data (see GUIDATA)
0386 resetButtonColors(handles);
0387 set(handles.button_23, 'BackgroundColor','green');
0388 setappdata(handles.frame_1, 'ROI', 23);
0389 update_ROI_DATA(handles);
0390 
0391 % --- Executes on button press in button_24.
0392 function button_24_Callback(hObject, eventdata, handles)
0393 % hObject    handle to button_24 (see GCBO)
0394 % eventdata  reserved - to be defined in a future version of MATLAB
0395 % handles    structure with handles and user data (see GUIDATA)
0396 resetButtonColors(handles);
0397 set(handles.button_24, 'BackgroundColor','green');
0398 setappdata(handles.frame_1, 'ROI', 24);
0399 update_ROI_DATA(handles);
0400 
0401 % --- Executes on button press in button_other.
0402 function button_other_Callback(hObject, eventdata, handles)
0403 % hObject    handle to button_other (see GCBO)
0404 % eventdata  reserved - to be defined in a future version of MATLAB
0405 % handles    structure with handles and user data (see GUIDATA)
0406 resetButtonColors(handles);
0407 set(handles.button_other, 'BackgroundColor','green');
0408 setappdata(handles.frame_1, 'ROI', 26);
0409 update_ROI_DATA(handles);
0410 
0411 % --- Executes on button press in button_load.
0412 function button_load_Callback(hObject, eventdata, handles)
0413 % hObject    handle to button_load (see GCBO)
0414 % eventdata  reserved - to be defined in a future version of MATLAB
0415 % handles    structure with handles and user data (see GUIDATA)
0416 
0417 [subject_dir] = uigetdir('/raid/projects/multiwork/experiment_12/included', 'Select a Subject Directory');
0418 [~, subject, ~] = fileparts(subject_dir);
0419 frames = dir([subject_dir '/cam01_frames_p/*.jpg']);
0420 num_frames = length(frames);
0421 % DEBUG
0422 %num_frames = min(num_frames, 6000);
0423 
0424 % SET ALL IMPORTANT GUI VARIABLES
0425 setappdata(handles.frame_1, 'NUM_FRAMES', num_frames);
0426 setappdata(handles.frame_1, 'SUBJECT_DIR', subject_dir);
0427 setappdata(handles.frame_1, 'SUBJECT', subject);
0428 
0429 % CECK IF DATA EXISTS
0430 coder_name = getappdata(handles.frame_1, 'CODER_NAME');
0431 if isempty(coder_name)
0432     existing_data = [subject_dir '/extra_p/' subject '_ROI.mat'];
0433 else
0434     existing_data = [subject_dir '/extra_p/' subject '_ROI_' coder_name '.mat'];
0435 end
0436 if exist(existing_data) == 2
0437     load(existing_data); % ROI_DATA
0438     setappdata(handles.frame_1, 'ROI_DATA', ROI_DATA);
0439     last_coded = get_last_frame_coded(handles);
0440     setappdata(handles.frame_1, 'CURRENT_FRAME', last_coded);
0441     setappdata(handles.frame_1, 'ROI', ROI_DATA(last_coded).ROI);
0442     highlightButton(handles, ROI_DATA(last_coded).ROI);
0443 else
0444     % SET UP DATA VARIABLE
0445     ROI_DATA = struct();
0446     for f = 1:num_frames
0447       ROI_DATA(f).frame_name = ['img_' num2str(f) '.jpg'];
0448       ROI_DATA(f).ROI = 0;
0449       ROI_DATA(f).is_coded = 0;
0450     end
0451     setappdata(handles.frame_1, 'ROI_DATA', ROI_DATA);
0452     setappdata(handles.frame_1, 'CURRENT_FRAME', 1);
0453     setappdata(handles.frame_1, 'ROI', 0);
0454 end
0455 assignin('base', 'ROI_DATA', ROI_DATA);
0456 
0457 initialize_image_objects(handles);
0458 
0459 update_GUI_controlls(handles);
0460 update_GUI_views(handles);
0461 
0462 % --- Executes on button press in button_next.
0463 function button_next_Callback(hObject, eventdata, handles)
0464 % hObject    handle to button_next (see GCBO)
0465 % eventdata  reserved - to be defined in a future version of MATLAB
0466 % handles    structure with handles and user data (see GUIDATA)
0467 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0468 num_frames = getappdata(handles.frame_1, 'NUM_FRAMES');
0469 if current_frame < num_frames
0470     setappdata(handles.frame_1, 'CURRENT_FRAME', current_frame+1);
0471     update_ROI_DATA(handles, current_frame:current_frame+1);
0472 
0473     update_GUI_controlls(handles);
0474     update_GUI_views(handles);
0475 end
0476 
0477 
0478 % --- Executes on button press in button_next_3.
0479 function button_next_3_Callback(hObject, eventdata, handles)
0480 % hObject    handle to button_next_3 (see GCBO)
0481 % eventdata  reserved - to be defined in a future version of MATLAB
0482 % handles    structure with handles and user data (see GUIDATA)
0483 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0484 num_frames = getappdata(handles.frame_1, 'NUM_FRAMES');
0485 if current_frame + 3 <= num_frames
0486   setappdata(handles.frame_1, 'CURRENT_FRAME', current_frame+3);
0487   update_ROI_DATA(handles, current_frame:current_frame+3);
0488 else
0489   setappdata(handles.frame_1, 'CURRENT_FRAME', num_frames);
0490   update_ROI_DATA(handles, current_frame:num_frames);
0491 end
0492 update_GUI_controlls(handles);
0493 update_GUI_views(handles);
0494 
0495 % --- Executes on button press in button_prev.
0496 function button_prev_Callback(hObject, eventdata, handles)
0497 % hObject    handle to button_prev (see GCBO)
0498 % eventdata  reserved - to be defined in a future version of MATLAB
0499 % handles    structure with handles and user data (see GUIDATA)
0500 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0501 if current_frame > 1
0502     setappdata(handles.frame_1, 'CURRENT_FRAME', current_frame-1);
0503     current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0504     ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0505     roi = ROI_DATA(current_frame).ROI;
0506     setappdata(handles.frame_1, 'ROI', roi);
0507     update_GUI_controlls(handles);
0508     update_GUI_views(handles);
0509 end
0510 
0511 % --- Executes on button press in button_prev_3.
0512 function button_prev_3_Callback(hObject, eventdata, handles)
0513 % hObject    handle to button_prev_3 (see GCBO)
0514 % eventdata  reserved - to be defined in a future version of MATLAB
0515 % handles    structure with handles and user data (see GUIDATA)
0516 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0517 if current_frame - 3 >= 1
0518   setappdata(handles.frame_1, 'CURRENT_FRAME', current_frame-3);
0519 else
0520   setappdata(handles.frame_1, 'CURRENT_FRAME', 1);
0521 end
0522 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0523 ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0524 roi = ROI_DATA(current_frame).ROI;
0525 setappdata(handles.frame_1, 'ROI', roi);
0526 update_GUI_controlls(handles);
0527 update_GUI_views(handles);
0528 
0529 
0530 function [] = update_GUI_controlls(handles)
0531 % update subject info
0532 subject = getappdata(handles.frame_1, 'SUBJECT');
0533 s = sprintf('Loaded: %s', subject);
0534 set(handles.text_loaded, 'String', s);
0535 % update frame info
0536 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0537 num_frames = getappdata(handles.frame_1, 'NUM_FRAMES');
0538 s = sprintf('Frame %d/%d (%d%%)', current_frame, num_frames, round(100*current_frame/num_frames));
0539 set(handles.text_frame_info, 'String', s);
0540 set(handles.edit_frame_number, 'String', num2str(current_frame));
0541 % show laste coded frame
0542 s = sprintf('Coded until frame: %d', get_last_frame_coded(handles));
0543 set(handles.text_last_coded, 'String', s);
0544 % highlight ROI button
0545 ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0546 roi = ROI_DATA(current_frame).ROI;
0547 highlightButton(handles, roi);
0548 % if I'm in safe mode and beyond the last coded frame, disable buttons
0549 save_mode = getappdata(handles.frame_1, 'SAFE_MODE');
0550 if save_mode && current_frame > get_last_frame_coded(handles)
0551     toggleButtons(handles, 'off');
0552 else
0553     toggleButtons(handles, 'on');
0554 end
0555 
0556 function [] = update_GUI_views(handles)
0557 subject_dir = getappdata(handles.frame_1, 'SUBJECT_DIR');
0558 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0559 img_view = imread([subject_dir '/cam01_frames_p/img_' num2str(current_frame) '.jpg']);
0560 img_third = imread([subject_dir '/cam03_frames_p/img_' num2str(current_frame) '.jpg']);
0561 img_third = img_third(60:420, :, :); % crop black bars
0562 img_eye = imread([subject_dir '/cam05_frames_p/img_' num2str(current_frame) '.jpg']);
0563 img_parent = imread([subject_dir '/cam08_frames_p/img_' num2str(current_frame) '.jpg']);
0564 % imshow(img_view, 'Parent', handles.frame_1);
0565 % imshow(img_eye, 'Parent', handles.frame_2);
0566 % imshow(img_third, 'Parent', handles.frame_3);
0567 % imshow(img_parent, 'Parent', handles.frame_4);
0568 s = getappdata(handles.frame_1, 's');
0569 v = getappdata(handles.frame_1, 'v');
0570 e = getappdata(handles.frame_1, 'e');
0571 n = getappdata(handles.frame_1, 'n');
0572 set(s,'CData', img_view);
0573 set(v,'CData', img_eye);
0574 set(e,'CData', img_third);
0575 set(n,'CData', img_parent);
0576 
0577 function [] = resetButtonColors(handles)
0578 grey = [0.941 0.941 0.941];
0579 set(handles.button_1, 'BackgroundColor', grey); %240 240 240
0580 set(handles.button_2, 'BackgroundColor', grey);
0581 set(handles.button_3, 'BackgroundColor', grey);
0582 set(handles.button_4, 'BackgroundColor', grey);
0583 set(handles.button_5, 'BackgroundColor', grey);
0584 set(handles.button_6, 'BackgroundColor', grey);
0585 set(handles.button_7, 'BackgroundColor', grey);
0586 set(handles.button_8, 'BackgroundColor', grey);
0587 set(handles.button_9, 'BackgroundColor', grey);
0588 set(handles.button_10, 'BackgroundColor', grey);
0589 set(handles.button_11, 'BackgroundColor', grey);
0590 set(handles.button_12, 'BackgroundColor', grey);
0591 set(handles.button_13, 'BackgroundColor', grey);
0592 set(handles.button_14, 'BackgroundColor', grey);
0593 set(handles.button_15, 'BackgroundColor', grey);
0594 set(handles.button_16, 'BackgroundColor', grey);
0595 set(handles.button_17, 'BackgroundColor', grey);
0596 set(handles.button_18, 'BackgroundColor', grey);
0597 set(handles.button_19, 'BackgroundColor', grey);
0598 set(handles.button_20, 'BackgroundColor', grey);
0599 set(handles.button_21, 'BackgroundColor', grey);
0600 set(handles.button_22, 'BackgroundColor', grey);
0601 set(handles.button_23, 'BackgroundColor', grey);
0602 set(handles.button_24, 'BackgroundColor', grey);
0603 set(handles.button_none, 'BackgroundColor', grey);
0604 set(handles.button_face, 'BackgroundColor', grey);
0605 set(handles.button_other, 'BackgroundColor', grey);
0606 
0607 function [] = update_ROI_DATA(handles, frames);
0608 safe_mode = getappdata(handles.frame_1, 'SAFE_MODE');
0609 % safe mode only allows changing current frame, i.e. calls where frames argument is empty
0610 if nargin < 2
0611     f = getappdata(handles.frame_1, 'CURRENT_FRAME');
0612     ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0613     ROI = getappdata(handles.frame_1, 'ROI');
0614     ROI_DATA(f).ROI = ROI;
0615 else
0616     ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0617     if ~safe_mode
0618         ROI = getappdata(handles.frame_1, 'ROI');
0619         num_frames = getappdata(handles.frame_1, 'NUM_FRAMES');
0620         for f = frames
0621             ROI_DATA(f).ROI = ROI;
0622             ROI_DATA(f).is_coded = 1;
0623         end
0624         % reset future frames in normal mode
0625         for f = frames(end)+1:num_frames
0626             ROI_DATA(f).ROI = 0;
0627             ROI_DATA(f).is_coded = 0;
0628         end
0629     end
0630 end
0631 % update data internally
0632 assignin('base', 'ROI_DATA', ROI_DATA);
0633 setappdata(handles.frame_1, 'ROI_DATA', ROI_DATA);
0634 % ... and save file
0635 coder_name = getappdata(handles.frame_1, 'CODER_NAME');
0636 subject_name = getappdata(handles.frame_1, 'SUBJECT');
0637 subject_dir = getappdata(handles.frame_1, 'SUBJECT_DIR');
0638 cstream_roi = data_to_cstream(ROI_DATA);
0639 if isempty(coder_name)
0640     save([subject_dir '/extra_p/' subject_name '_ROI.mat'], 'ROI_DATA');
0641   %save([subject_dir '/derived/cstream_eye_roi_child.mat'], 'cstream_roi');
0642   record_variable(get_subject_id_from_folder(handles), 'cstream_eye_roi_child', cstream_roi);
0643 else
0644     save([subject_dir '/extra_p/' subject_name '_ROI_' coder_name '.mat'], 'ROI_DATA');
0645   % save([subject_dir '/extra_p/cstream_eye_roi_child_' coder_name '.mat'], 'cstream_roi');
0646   record_variable_into_specified_directory(get_subject_id_from_folder(handles), 'extra_p', ['cstream_eye_roi_child_' coder_name], cstream_roi);
0647 end
0648 
0649 % DEBUG
0650 % roi = [ROI_DATA(:).ROI];
0651 % coded = logical([ROI_DATA(:).is_coded]);
0652 % roi = roi(coded);
0653 % [1:length(roi); roi]
0654 
0655 function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
0656 % hObject    handle to figure1 (see GCBO)
0657 % eventdata  structure with the following fields (see MATLAB.UI.FIGURE)
0658 % Key: name of the key that was pressed, in lower case
0659 % Character: character interpretation of the key(s) that was pressed
0660 % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
0661 % handles    structure with handles and user data (see GUIDATA)
0662 switch eventdata.Key
0663   case 'rightarrow'
0664     button_next_3_Callback(hObject, eventdata, handles);
0665   case 'leftarrow'
0666     button_prev_3_Callback(hObject, eventdata, handles);
0667   case 'uparrow'
0668     button_prev_Callback(hObject, eventdata, handles);
0669   case 'downarrow'
0670     button_next_Callback(hObject, eventdata, handles);
0671 end
0672 
0673 function edit_frame_number_Callback(hObject, eventdata, handles)
0674 % hObject    handle to edit_frame_number (see GCBO)
0675 % eventdata  reserved - to be defined in a future version of MATLAB
0676 % handles    structure with handles and user data (see GUIDATA)
0677 
0678 % Hints: get(hObject,'String') returns contents of edit_frame_number as text
0679 %        str2double(get(hObject,'String')) returns contents of edit_frame_number as a double
0680 jump_to = str2double(get(hObject,'String'));
0681 num_frames = getappdata(handles.frame_1, 'NUM_FRAMES');
0682 
0683 if isnumeric(jump_to) && ~isempty(num_frames) && jump_to >= 1 && jump_to <= num_frames
0684   setappdata(handles.frame_1, 'CURRENT_FRAME', jump_to);
0685   update_GUI_controlls(handles);
0686   update_GUI_views(handles);
0687 end
0688 
0689 % --- Executes during object creation, after setting all properties.
0690 function edit_frame_number_CreateFcn(hObject, eventdata, handles)
0691 % hObject    handle to edit_frame_number (see GCBO)
0692 % eventdata  reserved - to be defined in a future version of MATLAB
0693 % handles    empty - handles not created until after all CreateFcns called
0694 
0695 % Hint: edit controls usually have a white background on Windows.
0696 %       See ISPC and COMPUTER.
0697 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0698     set(hObject,'BackgroundColor','white');
0699 end
0700 
0701 % --- Executes on button press in safe_mode_box.
0702 function safe_mode_box_Callback(hObject, eventdata, handles)
0703 % hObject    handle to safe_mode_box (see GCBO)
0704 % eventdata  reserved - to be defined in a future version of MATLAB
0705 % handles    structure with handles and user data (see GUIDATA)
0706 
0707 % Hint: get(hObject,'Value') returns toggle state of safe_mode_box
0708 safe_mode = get(hObject,'Value');
0709 
0710 disp('Sven 123')
0711 
0712 if safe_mode
0713     %toggleButtons(handles, 'off');
0714     setappdata(handles.frame_1, 'SAFE_MODE', 1);
0715     set(handles.edit_frame_number, 'Enable', 'on');
0716 else
0717     set(handles.edit_frame_number, 'Enable', 'off');
0718     %toggleButtons(handles, 'on');
0719     setappdata(handles.frame_1, 'SAFE_MODE', 0);
0720 
0721     % if current frame > last coded frame, go to last coded frame automatically
0722     %once save mode is turned 'off'
0723     disp('test 3 bla');
0724     last_coded = get_last_frame_coded(handles)
0725     current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME')
0726     if current_frame > last_coded
0727         setappdata(handles.frame_1, 'CURRENT_FRAME', last_coded);
0728         ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0729         setappdata(handles.frame_1, 'ROI', ROI_DATA(last_coded).ROI);
0730         update_GUI_views(handles);
0731         update_GUI_controlls(handles);
0732     end
0733 end
0734 
0735 function [] = toggleButtons(handles, state)
0736 set(handles.button_1, 'Enable', state); 
0737 set(handles.button_2, 'Enable', state); 
0738 set(handles.button_3, 'Enable', state); 
0739 set(handles.button_4, 'Enable', state); 
0740 set(handles.button_5, 'Enable', state); 
0741 set(handles.button_6, 'Enable', state); 
0742 set(handles.button_7, 'Enable', state); 
0743 set(handles.button_8, 'Enable', state); 
0744 set(handles.button_9, 'Enable', state);
0745 set(handles.button_10, 'Enable', state);
0746 set(handles.button_11, 'Enable', state); 
0747 set(handles.button_12, 'Enable', state); 
0748 set(handles.button_13, 'Enable', state); 
0749 set(handles.button_14, 'Enable', state); 
0750 set(handles.button_15, 'Enable', state); 
0751 set(handles.button_16, 'Enable', state); 
0752 set(handles.button_17, 'Enable', state); 
0753 set(handles.button_18, 'Enable', state); 
0754 set(handles.button_19, 'Enable', state); 
0755 set(handles.button_20, 'Enable', state); 
0756 set(handles.button_21, 'Enable', state); 
0757 set(handles.button_22, 'Enable', state); 
0758 set(handles.button_23, 'Enable', state); 
0759 set(handles.button_24, 'Enable', state); 
0760 set(handles.button_none, 'Enable', state); 
0761 set(handles.button_face, 'Enable', state); 
0762 set(handles.button_other, 'Enable', state);
0763 
0764 function [] = highlightButton(handles, toy_id)
0765 resetButtonColors(handles);
0766 switch toy_id
0767     case 0
0768         set(handles.button_none, 'BackgroundColor','green');
0769     case 1
0770         set(handles.button_1, 'BackgroundColor','green');
0771     case 2
0772         set(handles.button_2, 'BackgroundColor','green');
0773     case 3
0774         set(handles.button_3, 'BackgroundColor','green');
0775     case 4
0776         set(handles.button_4, 'BackgroundColor','green');
0777     case 5
0778         set(handles.button_5, 'BackgroundColor','green');
0779     case 6
0780         set(handles.button_6, 'BackgroundColor','green');
0781     case 7
0782         set(handles.button_7, 'BackgroundColor','green');
0783     case 8
0784         set(handles.button_8, 'BackgroundColor','green');
0785     case 9
0786         set(handles.button_9, 'BackgroundColor','green');
0787     case 10
0788         set(handles.button_10, 'BackgroundColor','green');
0789     case 11
0790         set(handles.button_11, 'BackgroundColor','green');
0791     case 12
0792         set(handles.button_12, 'BackgroundColor','green');
0793     case 13
0794         set(handles.button_13, 'BackgroundColor','green');
0795     case 14
0796         set(handles.button_14, 'BackgroundColor','green');
0797     case 15
0798         set(handles.button_15, 'BackgroundColor','green');
0799     case 16
0800         set(handles.button_16, 'BackgroundColor','green');
0801     case 17
0802         set(handles.button_17, 'BackgroundColor','green');
0803     case 18
0804         set(handles.button_18, 'BackgroundColor','green');
0805     case 19
0806         set(handles.button_19, 'BackgroundColor','green');
0807     case 20
0808         set(handles.button_20, 'BackgroundColor','green');
0809     case 21
0810         set(handles.button_21, 'BackgroundColor','green');
0811     case 22
0812         set(handles.button_22, 'BackgroundColor','green');
0813     case 23
0814         set(handles.button_23, 'BackgroundColor','green');
0815     case 24
0816         set(handles.button_24, 'BackgroundColor','green');
0817     case 25
0818         set(handles.button_face, 'BackgroundColor','green');
0819     otherwise
0820         set(handles.button_other, 'BackgroundColor','green');
0821 end
0822 
0823 function last_coded = get_last_frame_coded(handles)
0824 ROI_DATA = getappdata(handles.frame_1, 'ROI_DATA');
0825 % HACK WHILE PEOPE ARE TESTING PROGRAM (!)
0826 % last_coded = length(find([ROI_DATA(:).is_coded] == 1));
0827 last_coded = max(find([ROI_DATA(:).is_coded] == 1));
0828 if last_coded == 0
0829     last_coded = 1;
0830 end
0831 
0832 function [] = initialize_image_objects(handles)
0833 subject_dir = getappdata(handles.frame_1, 'SUBJECT_DIR');
0834 current_frame = getappdata(handles.frame_1, 'CURRENT_FRAME');
0835 img_view = imread([subject_dir '/cam01_frames_p/img_' num2str(current_frame) '.jpg']);
0836 img_third = imread([subject_dir '/cam03_frames_p/img_' num2str(current_frame) '.jpg']);
0837 img_third = img_third(60:420, :, :); % crop black bars
0838 img_eye = imread([subject_dir '/cam05_frames_p/img_' num2str(current_frame) '.jpg']);
0839 img_parent = imread([subject_dir '/cam08_frames_p/img_' num2str(current_frame) '.jpg']);
0840 
0841 s = imshow(img_view, 'Parent', handles.frame_1);
0842 v = imshow(img_eye, 'Parent', handles.frame_2);
0843 e = imshow(img_third, 'Parent', handles.frame_3);
0844 n = imshow(img_parent, 'Parent', handles.frame_4);
0845 % set(s,'EraseMode','none');
0846 % set(v,'EraseMode','none');
0847 % set(e,'EraseMode','none');
0848 % set(n,'EraseMode','none');
0849 setappdata(handles.frame_1, 's', s);
0850 setappdata(handles.frame_1, 'v', v);
0851 setappdata(handles.frame_1, 'e', e);
0852 setappdata(handles.frame_1, 'n', n);
0853 
0854 function [cstream_roi] = data_to_cstream(ROI_DATA)
0855 is_coded = [ROI_DATA(:).is_coded] == 1;
0856 index = 1:length(find(is_coded));
0857 time = (index-1) * 1/30 + 30;
0858 roi = [ROI_DATA(is_coded).ROI];
0859 cstream_roi = [time' roi'];
0860 
0861 function ReleaseFocus(fig)
0862 set(findobj(fig, 'Type', 'uicontrol'), 'Enable', 'off');
0863 drawnow;
0864 set(findobj(fig, 'Type', 'uicontrol'), 'Enable', 'on');
0865 
0866 function subject_id = get_subject_id_from_folder(handles)
0867 folder = getappdata(handles.frame_1, 'SUBJECT');
0868 tempy = strsplit(folder, '_');
0869 s_date = str2num(tempy{2});
0870 s_id = str2num(tempy{3});
0871 table = read_subject_table();
0872 s_r = find(table(:,3) == s_date & table(:,4) == s_id);
0873 if isempty(s_r)
0874   error('Cannot find subject id in subject table');
0875 else
0876   subject_id = table(s_r, 1)
0877 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005