Home > coding_tools > object_annotation > label_toys.m

label_toys

PURPOSE ^

LABEL_TOYS MATLAB code for label_toys.fig

SYNOPSIS ^

function varargout = label_toys(varargin)

DESCRIPTION ^

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

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

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

      LABEL_TOYS('Property','Value',...) creates a new LABEL_TOYS or raises the
      existing singleton*.  Starting from the left, property value pairs are
      applied to the GUI before label_toys_OpeningFcn gets called.  An
      unrecognized property name or invalid value makes property application
      stop.  All inputs are passed to label_toys_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 = label_toys(varargin)
0002     % LABEL_TOYS MATLAB code for label_toys.fig
0003     %      LABEL_TOYS, by itself, creates a new LABEL_TOYS or raises the existing
0004     %      singleton*.
0005     %
0006     %      H = LABEL_TOYS returns the handle to a new LABEL_TOYS or the handle to
0007     %      the existing singleton*.
0008     %
0009     %      LABEL_TOYS('CALLBACK',hObject,eventData,handles,...) calls the local
0010     %      function named CALLBACK in LABEL_TOYS.M with the given input arguments.
0011     %
0012     %      LABEL_TOYS('Property','Value',...) creates a new LABEL_TOYS or raises the
0013     %      existing singleton*.  Starting from the left, property value pairs are
0014     %      applied to the GUI before label_toys_OpeningFcn gets called.  An
0015     %      unrecognized property name or invalid value makes property application
0016     %      stop.  All inputs are passed to label_toys_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 label_toys
0024 
0025     % Last Modified by GUIDE v2.5 01-Sep-2015 12:07:40
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', @label_toys_OpeningFcn, ...
0032                        'gui_OutputFcn',  @label_toys_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 end
0046 
0047 
0048 % --- Executes just before label_toys is made visible.
0049 function label_toys_OpeningFcn(hObject, eventdata, handles, varargin)
0050     % This function has no output args, see OutputFcn.
0051     % hObject    handle to figure
0052     % eventdata  reserved - to be defined in a future version of MATLAB
0053     % handles    structure with handles and user data (see GUIDATA)
0054     % varargin   command line arguments to label_toys (see VARARGIN)
0055 
0056     % Choose default command line output for label_toys
0057     handles.output = hObject;
0058 
0059     % Update handles structure
0060     guidata(hObject, handles);
0061 
0062     % UIWAIT makes label_toys wait for user response (see UIRESUME)
0063     % uiwait(handles.figure1);
0064 end
0065 
0066 % --- Outputs from this function are returned to the command line.
0067 function varargout = label_toys_OutputFcn(hObject, eventdata, handles) 
0068     % varargout  cell array for returning output args (see VARARGOUT);
0069     % hObject    handle to figure
0070     % eventdata  reserved - to be defined in a future version of MATLAB
0071     % handles    structure with handles and user data (see GUIDATA)
0072 
0073     % Get default command line output from handles structure
0074     varargout{1} = handles.output;
0075 
0076     % git add supporting functions
0077     addpath(genpath('supporting_functions'));
0078 
0079     % turn off axis
0080     set(handles.frame,'xcolor',get(gcf,'color'));
0081     set(handles.frame,'ycolor',get(gcf,'color'));
0082     set(handles.frame,'ytick',[]);
0083     set(handles.frame,'xtick',[]);
0084     set(handles.toy_img,'xcolor',get(gcf,'color'));
0085     set(handles.toy_img,'ycolor',get(gcf,'color'));
0086     set(handles.toy_img,'ytick',[]);
0087     set(handles.toy_img,'xtick',[]);
0088 
0089     % create toy list
0090     toys = {'helmet', 'house', 'blue car', 'flower', 'elephant', 'snowman',...
0091         'rabbit', 'spongebob', 'turtle', 'gavel', 'bug', 'mantis', ...
0092         'green car', 'saw', 'doll', 'phone', 'rubik''s cube', 'rake', ...
0093         'truck', 'white/blue car', 'ladybug', 'purple cube', 'bed', ...
0094         'ball in cube'};
0095     for nr = 1:length(toys)
0096         toys{nr} = [toys{nr} ' (' num2str(nr) ')'];
0097     end
0098     set(handles.toy_list, 'String', toys);
0099     
0100     % create toy box colors
0101     rng(123);
0102     colors = rand(24,3);
0103     
0104     % create toy thumbnail imags
0105     thumbnails = cell(length(toys), 1);
0106     for i = 1:length(toys)
0107         thumbnails{i} = imread(['toys/' num2str(i) '.jpg']);
0108     end
0109     imshow(thumbnails{1}, 'Parent', handles.toy_img);
0110     
0111     % setappdata(handles.frame, 'toy_id', 1);
0112     
0113     % SET ALL IMPORTANT GUI VARIABLES THAT ARE ABSOLUTE...
0114     setappdata(handles.frame, 'THUMBNAILS', thumbnails);
0115     setappdata(handles.frame, 'NUM_TOYS', length(toys));
0116     setappdata(handles.frame, 'FAST_MODE', 1);
0117     setappdata(handles.frame, 'TOYS_LIST', toys);
0118     setappdata(handles.frame, 'TOY_COLORS', colors);
0119 
0120     % set interface to FAST MODE per default
0121     change_mode_interface(handles);
0122 end
0123 
0124 % --- Executes on button press in load_button.
0125 function load_button_Callback(hObject, eventdata, handles)
0126     % hObject    handle to load_button (see GCBO)
0127     % eventdata  reserved - to be defined in a future version of MATLAB
0128     % handles    structure with handles and user data (see GUIDATA)
0129 
0130     % load in text file with image list
0131     [file_name, file_dir] = uigetfile(fullfile(filesep, 'cantor', 'space', 'experiment_11', 'frame_lists', '*.txt'), 'Select a text file that contains a list of frames');
0132     fid = fopen(fullfile(file_dir, file_name));
0133     frame_list = textscan(fid, '%s');
0134     file_names = frame_list{1};
0135     num_frames = size(file_names, 1);
0136 
0137     % generate data name based on text file name
0138     % file_name = strsplit(file_name, '_');
0139     % file_name = strrep(file_name{end}, '.txt', '.mat');
0140     file_name = strrep(file_name, '.txt', '.mat');
0141     data_name = ['annotation_data_' file_name];
0142 
0143     % assume directory for matlab file is the same at for the text file
0144     data_dir = file_dir;
0145     
0146     % check if a matlab file exists
0147     if exist([data_dir data_name], 'file') == 2
0148         load([data_dir data_name]); % loads annotation_data and status
0149     else
0150         % initialize annotation_data and status
0151         annotation_data = struct('frame_name',{},'boxes', {});
0152         num_toys = getappdata(handles.frame, 'NUM_TOYS');
0153         for f = 1:num_frames
0154             annotation_data(f).frame_name = file_names{f};
0155             annotation_data(f).boxes = nan(num_toys, 4);
0156         end
0157         status.current_toy = 1;
0158         status.current_frame = 1;
0159         status.data_name = data_name;
0160         status.data_dir = data_dir;
0161     end
0162 
0163     % SET ALL IMPORTANT GUI VARIABLES
0164     setappdata(handles.frame, 'ANNOTATION_DATA', annotation_data);
0165     setappdata(handles.frame, 'STATUS', status);
0166     setappdata(handles.frame, 'GUI_FRAME', status.current_frame);
0167     setappdata(handles.frame, 'GUI_TOY', status.current_toy);
0168     setappdata(handles.frame, 'NUM_FRAMES', num_frames);
0169     setappdata(handles.frame, 'DATA_DIR', data_dir);
0170 
0171     % update everything in GUI to current status
0172     update_GUI_elements(handles);
0173 
0174 end
0175 
0176 % --- Executes on button press in next_button.
0177 function next_button_Callback(hObject, eventdata, handles)
0178     % hObject    handle to next_button (see GCBO)
0179     % eventdata  reserved - to be defined in a future version of MATLAB
0180     % handles    structure with handles and user data (see GUIDATA)
0181 
0182     num_frames = getappdata(handles.frame, 'NUM_FRAMES');
0183     gui_frame = getappdata(handles.frame, 'GUI_FRAME');
0184 
0185     if gui_frame < num_frames
0186         gui_frame = gui_frame + 1;
0187         setappdata(handles.frame, 'GUI_FRAME', gui_frame);
0188 
0189         if getappdata(handles.frame, 'FAST_MODE')
0190             status = getappdata(handles.frame, 'STATUS');
0191             status.current_frame = gui_frame;
0192             setappdata(handles.frame, 'STATUS', status);
0193         end
0194 
0195         update_GUI_elements(handles);
0196     else
0197 
0198         if getappdata(handles.frame, 'FAST_MODE');
0199 
0200             status = getappdata(handles.frame, 'STATUS');
0201             num_toys = getappdata(handles.frame, 'NUM_TOYS');
0202 
0203             if status.current_toy < num_toys
0204 
0205                 status.current_toy = status.current_toy + 1;
0206                 status.current_frame = 1;
0207 
0208                 setappdata(handles.frame, 'STATUS', status);
0209                 setappdata(handles.frame, 'GUI_TOY', status.current_toy);
0210                 setappdata(handles.frame, 'GUI_FRAME', status.current_frame);
0211 
0212                 update_GUI_elements(handles);
0213             end
0214         end
0215     end
0216 
0217     save_data(handles);
0218 end
0219 
0220 % --- Executes on button press in prev_button.
0221 function prev_button_Callback(hObject, eventdata, handles)
0222     % hObject    handle to prev_button (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 
0226     gui_frame = getappdata(handles.frame, 'GUI_FRAME');
0227 
0228     if gui_frame > 1
0229 
0230         gui_frame = gui_frame - 1;
0231         setappdata(handles.frame, 'GUI_FRAME', gui_frame);
0232 
0233         if getappdata(handles.frame, 'FAST_MODE')
0234             status = getappdata(handles.frame, 'STATUS');
0235             status.current_frame = gui_frame;
0236             setappdata(handles.frame, 'STATUS', status);
0237         end
0238 
0239         update_GUI_elements(handles);
0240     else
0241         
0242         if getappdata(handles.frame, 'FAST_MODE');
0243 
0244             status = getappdata(handles.frame, 'STATUS');
0245             num_frames = getappdata(handles.frame, 'NUM_FRAMES');
0246 
0247             if status.current_toy > 1
0248 
0249                 status.current_toy = status.current_toy - 1;
0250                 status.current_frame = num_frames;
0251 
0252                 setappdata(handles.frame, 'STATUS', status);
0253                 setappdata(handles.frame, 'GUI_TOY', status.current_toy);
0254                 setappdata(handles.frame, 'GUI_FRAME', status.current_frame);
0255 
0256                 update_GUI_elements(handles);
0257             end
0258         end
0259 
0260     end
0261 
0262     save_data(handles);
0263 end
0264 
0265 function edit_number_Callback(hObject, eventdata, handles)
0266     % hObject    handle to edit_number (see GCBO)
0267     % eventdata  reserved - to be defined in a future version of MATLAB
0268     % handles    structure with handles and user data (see GUIDATA)
0269     
0270     jump_to = str2double(get(hObject,'String'));
0271     num_frames = getappdata(handles.frame, 'NUM_FRAMES');
0272 
0273     if isnumeric(jump_to) && ~isempty(num_frames) && jump_to >= 1 && jump_to <= num_frames
0274         setappdata(handles.frame, 'GUI_FRAME', jump_to);
0275         update_GUI_elements(handles);
0276     end
0277 end
0278 
0279 
0280 % --- Executes on selection change in toy_list.
0281 function toy_list_Callback(hObject, eventdata, handles)
0282     % hObject    handle to toy_list (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     %contents = cellstr(get(hObject,'String'));
0286     toy_id = get(hObject,'Value');
0287     %toy = contents{toy_id};
0288     
0289     setappdata(handles.frame, 'GUI_TOY', toy_id);
0290     update_GUI_elements(handles);
0291     
0292     % thumbnails = getappdata(handles.frame, 'thumbnails');
0293     % imshow(thumbnails{toy_id}, 'Parent', handles.toy_img);
0294 end
0295 
0296 % --- Executes on button press in box_button.
0297 function box_button_Callback(hObject, eventdata, handles)
0298     % hObject    handle to box_button (see GCBO)
0299     % eventdata  reserved - to be defined in a future version of MATLAB
0300     % handles    structure with handles and user data (see GUIDATA)
0301 
0302     %disable other GUI elements until box is drawn
0303     set(handles.prev_button, 'Enable', 'off');
0304     set(handles.next_button, 'Enable', 'off');
0305     set(handles.load_button, 'Enable', 'off');
0306     set(handles.load_button, 'Enable', 'off');
0307     set(handles.box_button, 'Enable', 'off');
0308     set(handles.edit_number, 'Enable', 'off');
0309     set(handles.remove_box, 'Enable', 'off');
0310 
0311     % wait for rectangle
0312     h = imrect(handles.frame);
0313 
0314     toy_id = getappdata(handles.frame, 'GUI_TOY');
0315 
0316     % rectangle stuff
0317     colors = getappdata(handles.frame, 'TOY_COLORS');
0318     fcn = makeConstrainToRectFcn('imrect', get(handles.frame, 'Xlim'), get(handles.frame, 'Ylim'));
0319     setPositionConstraintFcn(h,fcn);
0320     setResizable(h, false);
0321     setColor(h, colors(toy_id, :));
0322     pos = getPosition(h);
0323     % make sure box is within image;
0324     pos = crop_box_to_image(pos);
0325 
0326     % get data to update
0327     annotation_data = getappdata(handles.frame, 'ANNOTATION_DATA');
0328     index = getappdata(handles.frame, 'GUI_FRAME');
0329 
0330     % update data with rectangle
0331     annotation_data(index).boxes(toy_id, :) = pos;
0332     setappdata(handles.frame, 'ANNOTATION_DATA', annotation_data);
0333 
0334     %enable other GUI elements
0335     set(handles.prev_button, 'Enable', 'on');
0336     set(handles.next_button, 'Enable', 'on');
0337     set(handles.load_button, 'Enable', 'on');
0338     set(handles.toy_list, 'Enable', 'on');
0339     set(handles.edit_number, 'Enable', 'on');
0340     set(handles.box_button, 'Enable', 'on');
0341     set(handles.remove_box, 'Enable', 'on');
0342 
0343     % save changes
0344     save_data(handles);
0345 end
0346 
0347 % --- Executes on selection change in edit_mode_menu.
0348 function edit_mode_menu_Callback(hObject, eventdata, handles)
0349     % hObject    handle to edit_mode_menu (see GCBO)
0350     % eventdata  reserved - to be defined in a future version of MATLAB
0351     % handles    structure with handles and user data (see GUIDATA)
0352 
0353     % Hints: contents = cellstr(get(hObject,'String')) returns edit_mode_menu contents as cell array
0354     %        contents{get(hObject,'Value')} returns selected item from edit_mode_menu
0355 
0356     edit_mode = get(hObject,'Value');
0357     if edit_mode == 1
0358 
0359         % reset all GUI elements to status
0360         status = getappdata(handles.frame, 'STATUS');
0361         setappdata(handles.frame, 'GUI_FRAME', status.current_frame);
0362         setappdata(handles.frame, 'GUI_TOY', status.current_toy);
0363         update_GUI_elements(handles);
0364 
0365         setappdata(handles.frame, 'FAST_MODE', 1);
0366         change_mode_interface(handles);
0367     else
0368         setappdata(handles.frame, 'FAST_MODE', 0);
0369         change_mode_interface(handles);
0370     end
0371 end
0372 
0373 % --- Executes on button press in remove_box.
0374 function remove_box_Callback(hObject, eventdata, handles)
0375     % hObject    handle to remove_box (see GCBO)
0376     % eventdata  reserved - to be defined in a future version of MATLAB
0377     % handles    structure with handles and user data (see GUIDATA)
0378     toy_id = getappdata(handles.frame, 'GUI_TOY');
0379     index = getappdata(handles.frame, 'GUI_FRAME');
0380     annotation_data = getappdata(handles.frame, 'ANNOTATION_DATA');
0381     
0382     % remove box from data and re-save
0383     annotation_data(index).boxes(toy_id, :) = nan(1, 4);
0384     setappdata(handles.frame, 'ANNOTATION_DATA', annotation_data);
0385     save_data(handles);
0386 
0387     update_GUI_elements(handles);
0388 end
0389 
0390 % --- Executes on key press with focus on figure1 and none of its controls.
0391 function figure1_KeyPressFcn(hObject, eventdata, handles)
0392     % hObject    handle to figure1 (see GCBO)
0393     % eventdata  structure with the following fields (see FIGURE)
0394     %   Key: name of the key that was pressed, in lower case
0395     %   Character: character interpretation of the key(s) that was pressed
0396     %   Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
0397     % handles    structure with handles and user data (see GUIDATA)
0398 
0399     switch eventdata.Key
0400         case 'rightarrow'
0401             next_button_Callback(hObject, eventdata, handles);
0402         case 'leftarrow'
0403             prev_button_Callback(hObject, eventdata, handles);
0404         case 'd'
0405             if getappdata(handles.frame, 'FAST_MODE')
0406                 fast_mode_draw_rectangle(hObject, eventdata, handles);
0407             end
0408     end
0409 end
0410 
0411 function [] = save_data(handles)
0412 
0413     annotation_data = getappdata(handles.frame, 'ANNOTATION_DATA');
0414     status = getappdata(handles.frame, 'STATUS');
0415 
0416     % write to workspace
0417     assignin('base', 'annotation_data', annotation_data);
0418     assignin('base', 'status', status);
0419 
0420     % write to disk
0421     save([status.data_dir status.data_name], 'annotation_data', 'status');
0422 end
0423 
0424 function [] = change_mode_interface(handles)
0425 
0426     fast_mode = getappdata(handles.frame, 'FAST_MODE');
0427 
0428     s1 = sprintf('%s\n%s', 'Fast Mode allows fast, key-based annotating of the currently highlighted toy.', ...
0429      'Keys: [d] to draw a box, [leftarrow] and [rightarrow] to go through frames');
0430 
0431     s2 = 'Edit Mode allows to go through all toys and manually add/remove boxes.';
0432 
0433     if fast_mode == 1 %fast mode
0434         set(handles.prev_button, 'Enable', 'off');
0435         set(handles.next_button, 'Enable', 'off');
0436         set(handles.box_button, 'Enable', 'off');
0437         set(handles.remove_box, 'Enable', 'off');
0438         set(handles.edit_number, 'Enable', 'off');
0439         set(handles.toy_list, 'Enable', 'off');
0440         set(handles.mode_text,'String', s1);
0441     else
0442         set(handles.prev_button, 'Enable', 'on');
0443         set(handles.next_button, 'Enable', 'on');
0444         set(handles.box_button, 'Enable', 'on');
0445         set(handles.remove_box, 'Enable', 'on');
0446         set(handles.edit_number, 'Enable', 'on');
0447         set(handles.toy_list, 'Enable', 'on');
0448         set(handles.mode_text,'String', s2);
0449     end
0450 end
0451 
0452 function [] = fast_mode_draw_rectangle(hObject, eventdata, handles)
0453 
0454     % wait for rectangle
0455     h = imrect(handles.frame);
0456 
0457     toy_id = getappdata(handles.frame, 'GUI_TOY');
0458 
0459     % rectangle stuff
0460     colors = getappdata(handles.frame, 'TOY_COLORS');
0461     fcn = makeConstrainToRectFcn('imrect', get(handles.frame, 'Xlim'), get(handles.frame, 'Ylim'));
0462     setPositionConstraintFcn(h,fcn);
0463     setResizable(h, false);
0464     setColor(h, colors(toy_id, :));
0465     pos = getPosition(h);
0466     % make sure box stays within image
0467     pos = crop_box_to_image(pos);
0468 
0469     % get data to update
0470     annotation_data = getappdata(handles.frame, 'ANNOTATION_DATA');
0471     index = getappdata(handles.frame, 'GUI_FRAME');
0472 
0473     % update data with rectangle
0474     annotation_data(index).boxes(toy_id, :) = pos;
0475     setappdata(handles.frame, 'ANNOTATION_DATA', annotation_data);
0476 
0477     % directly go to next frame
0478     next_button_Callback(hObject, eventdata, handles);
0479 end
0480 
0481 function [] = update_GUI_elements(handles)
0482     
0483     % update status info
0484     status = getappdata(handles.frame, 'STATUS');
0485     num_frames = getappdata(handles.frame, 'NUM_FRAMES');
0486     num_toys = getappdata(handles.frame, 'NUM_TOYS');
0487     s = sprintf('Toy %s/%s\nFrame %s/%s', num2str(status.current_toy), num2str(num_toys), num2str(status.current_frame), num2str(num_frames));
0488     set(handles.fast_mode_info, 'String', s);
0489 
0490     % update image
0491     render_image_with_boxes(handles);
0492 
0493     % update current frame
0494     index = getappdata(handles.frame, 'GUI_FRAME');
0495     set(handles.frame_info, 'String', ['Frame ' num2str(index) '/' num2str(num_frames)]);
0496     set(handles.edit_number, 'String', num2str(index));
0497 
0498     % update selected toy and thumbnail
0499     toy_id = getappdata(handles.frame, 'GUI_TOY');
0500     toy_thumbnails = getappdata(handles.frame, 'THUMBNAILS');
0501     imshow(toy_thumbnails{toy_id}, 'Parent', handles.toy_img);
0502     set(handles.toy_list, 'Value', toy_id);
0503 end
0504 
0505 function [] = render_image_with_boxes(handles)
0506 
0507     annotation_data = getappdata(handles.frame, 'ANNOTATION_DATA');
0508     index = getappdata(handles.frame, 'GUI_FRAME');
0509     img = imread(annotation_data(index).frame_name);
0510 
0511     toys = getappdata(handles.frame, 'TOYS_LIST');
0512     colors = getappdata(handles.frame, 'TOY_COLORS');
0513 
0514     % draw texts on images
0515     for b = 1:size(annotation_data(index).boxes, 1)
0516         if ~isnan(annotation_data(index).boxes(b, 1))
0517             pos = annotation_data(index).boxes(b, :);
0518             text = text2im(toys{b});
0519             text = cat(3, text, text, text)*255;
0520             text = imresize(text, 0.75);
0521             img = implace(img, text, round(pos(2)), round(pos(1)));
0522         end
0523     end
0524 
0525     % show image
0526     imshow(img, 'Parent', handles.frame);
0527     
0528     % overlay boxes
0529     for b = 1:size(annotation_data(index).boxes, 1)
0530         if ~isnan(annotation_data(index).boxes(b, 1))
0531             pos = annotation_data(index).boxes(b, :);
0532             color = colors(b, :);
0533             rectangle('Position', pos,...
0534                   'LineWidth',2,...
0535                   'EdgeColor', color, ...
0536                   'LineStyle','-', 'Parent', handles.frame);
0537 
0538             text = text2im(toys{b});
0539             text = cat(3, text, text, text)*255;
0540             text = imresize(text, 0.5);
0541             img = implace(img, text, round(pos(2)), round(pos(1)));
0542         end
0543     end
0544 end
0545 
0546 function box_out = crop_box_to_image(box_in)
0547     % box_in = [x y width height]
0548     image_w = 1280;
0549     image_h = 720;
0550 
0551     box_in = round(box_in);
0552     x1 = box_in(1);
0553     y1 = box_in(2);
0554     x2 = x1 + box_in(3);
0555     y2 = y1 + box_in(4);
0556 
0557     x1 = min(max(x1,1), image_w);
0558     y1 = min(max(y1,1), image_h);
0559     x2 = min(max(x2,2), image_w);
0560     y2 = min(max(y2,2), image_h);
0561 
0562     width = abs(x2 - x1) + 1;
0563     height = abs(y2 - y1) + 1;
0564 
0565     box_out = [x1 y1 width height];
0566 end
0567 
0568 
0569 % --- Executes when user attempts to close figure1.
0570 function figure1_CloseRequestFcn(hObject, eventdata, handles)
0571 % hObject    handle to figure1 (see GCBO)
0572 % eventdata  reserved - to be defined in a future version of MATLAB
0573 % handles    structure with handles and user data (see GUIDATA)
0574 
0575 % Hint: delete(hObject) closes the figure
0576 delete(hObject);
0577 exit();
0578 end

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