function selectButterflies ( s_img, s_dest ) % function selectButterflies ( s_img, s_dest ) % % BRIEF % Select bounding boxes for images, save those guys to a specified % folder, and keep track of everything with a small cache. % % INPUT % s_img -- string specifying name of image to be annotated % s_dest -- where to save cropped images to % % OUTPUT % none % s_cacheDest = './cacheButterflies.mat'; if ( exist ( s_cacheDest ) ) load ( s_cacheDest, 'cacheButterflies', 'i_counter' ); end im = imread ( s_img ); figImg = figure; figCrop = figure; b_continueSelection = true; i_numBoxesPerClick = 1; imWithBoxes = im; % i_linewidth = 3; partcolor{1} = [255,0,0]; if ( ~exist ( 'cacheButterflies' ) ) cacheButterflies = struct( 'name', 'rectangle' ) ; else idxSameImg = strcmp ( {cacheButterflies.name}, s_img); bBox = {cacheButterflies.rectangle}; bBoxSameImg = cell2mat(bBox(idxSameImg)'); imWithBoxes = drawBoxesToImg(imWithBoxes, bBoxSameImg, partcolor, i_linewidth); end if ( ~exist ( 'i_counter') ) i_counter = 1 ; end s_prompt = sprintf('Press enter for save+continue, r for retry, and X for abort\n'); while b_continueSelection figure ( figImg ); imshow ( imWithBoxes ); [xmin, ymin, xmax, ymax] = clickBoundingBoxes2D ( i_numBoxesPerClick ); xmin = int32(round(xmin)); ymin = int32(round(ymin)); xmax = int32(round(xmax)); ymax = int32(round(ymax)); imTmp = imcrop(im, [xmin, ymin, xmax-xmin, ymax-ymin]); figure ( figCrop ); imshow ( imTmp ); result = input(s_prompt, 's'); while ( ~isempty(result) && (strcmp(result,'r')==0) && (strcmp(result,'X')==0) ) disp(sprintf('Retry input!\n')) result = input(s_prompt, 's'); end if ( strcmp(result,'X') ) return; end if ( isempty(result) ) % write current proposal s_destFig = sprintf('%s_%03d.png',s_dest, i_counter); imwrite ( imTmp, s_destFig ); % save results to cache cacheButterflies( i_counter ).name = s_img; cacheButterflies( i_counter ).rectangle = [xmin,ymin,xmax,ymax]; i_counter = i_counter +1; save ( s_cacheDest, 'cacheButterflies', 'i_counter' ); % plot current result newproposal = [xmin,ymin,xmax,ymax]; imWithBoxes = drawBoxesToImg(imWithBoxes, newproposal, partcolor, i_linewidth); end end end