function Mark_4_RegionsBees() % Request the user to mark 4 regions in all .jpg images in an input % directory. Regions are defined by drawing polygons in the input image. % right-button click closes the region. Then use double click at the last % point to validate the region and pass to the next one. In case of drawing % error, press CTRL-C to abort the function and run the code again without % deleting previous results. The program checks if a locations file for the % current image exists and if so, skips it from the selecting region % process. %Typical Example of usage: % Mark_4_RegionsBees(); % (c) Gustavo Liñan Cembrano % IMSE-CNM-CSIC % linan@imse-cnm.csic.es clear all; close all; clc; IM_PATH=uigetdir([],'Select Image Folder'); cd(IM_PATH) DeletePrevious = questdlg('Delete previous regions?','Delete','No'); if(strcmp(DeletePrevious,'Yes')) delete('*.mat'); delete('*.tiff') elseif(strcmp(DeletePrevious,'Cancel')) return; else %Do nothing end %Getting File name structure FileName=dir('*.jpg'); NFiles=length(FileName); msgstr=sprintf('%d Images Found in directory',NFiles); h=msgbox(msgstr); pause(1); delete(h) for j=1:NFiles %% Accessing file CURRENT_FILE=FileName(j).name; OutFileName=strcat(CURRENT_FILE,'_Locations.mat'); %Only going through the loop if file with locations does not exist %no need to change j index FileExist=exist(OutFileName,'file'); if(FileExist~=0) msgstr=sprintf('%s exists in current path\n Skipping this file',OutFileName); h=msgbox(msgstr); pause(0.5); delete(h) else INPUT_IM=imread(CURRENT_FILE); imshow(INPUT_IM) Nregions=question(); if Nregions>=1 %% Marking regions h=msgbox('Mark region 1'); pause(0.2); close(h); h=impoly; wait(h); region1=createMask(h); region1=find(region1==1); end if(Nregions>=2) %% Marking regions h=msgbox('Mark region 2'); pause(0.2); close(h); h=impoly; wait(h); region2=createMask(h); region2=find(region2==1); end %% Marking regions if(Nregions>=3) h=msgbox('Mark region 3'); pause(0.2); close(h); h=impoly; wait(h); region3=createMask(h); region3=find(region3==1); end %% Marking regions if(Nregions==4) h=msgbox('Mark region 4'); pause(0.2); close(h); h=impoly; wait(h); region4=createMask(h); region4=find(region4==1); end %Saving to File. Do not change OutFileName variable %as it has to agree with what's defined in the entropy calculation code switch Nregions case 1 save(OutFileName,'region1','-v7.3') case 2 save(OutFileName,'region1','region2','-v7.3') case 3 save(OutFileName,'region1','region2','region3','-v7.3') case 4 save(OutFileName,'region1','region2','region3','region4','-v7.3') end end end close all; end function N=question(varargin) %Preguntamos por algo N=nargin; switch N case 0, prompt={'¿How many regions to be marked?'}; name='Nregions'; case 1, prompt={varargin{1}}; name='Question box'; end numlines=1; defaultanswer={''}; answer=inputdlg(prompt,name,numlines,defaultanswer); options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; N=str2double(answer); end