function ID=create_scene(templates) %lets the user choose object types (generator index for templates), %deformation strength, and noise level.Computes the deformed image ID. %templates are stored in the 3D array templates %1.ENTER. answer='y';objects=[];[l1,l2]=size(templates(:,:,1));I=zeros(l1,l2); 'To select a template type press ENTER' pause while answer =='y' val1=0;val2=0;val3=0;val4=0;val5=0; select_t pause close load types objects=[objects,val1+2*val2+3*val3+4*val4+5*val5]; answer=input('Do you want more objects in the scene ? Answer y/n','s') end nobjects=length(objects) %2. EUCLID. Apply Euclidean group SE(2) to templates for i=1:nobjects DX=0;DY=0;ROT=0; 'To apply Eucldean group to (next) template press ENTER' select_Euclid pause close load Euclid dx=DX;dy=DY;rot=ROT; Inew=Euclid([dx dy], rot, templates(:,:,objects(i))); I=max(I,Inew); end %3.CLUTTER, %compute cluttered background level=0; noise_create pause close load Noise 'clutter level=' level w=7;l=5;N=30;background=zeros(l1,l2); ws=[-round(w/2):round(w/2)]; ls=[-round(l/2):round(l/2)]; %start simulating clutter for i=1:ceil(rand(1)*N) x1=ceil(l1*rand(1)); x2=ceil(l2*rand(1)); v1=round(x1+ls);v2=round(x2+ws); v1=max(1,min(v1,l1));v2=max(1,min(v2,l2)); new=zeros(l1,l2);new(v1,v2)=level/200.*rand(1).*ones(length(v1),length(v2)); background=max(background, new); end background=diffeo(background,level/100); deflevel=0; def_create pause close load Noise 'deformation level=' deflevel %4.DIFFEO. I=diffeo(I,1.5*deflevel); %form cluttered and deformed image ID=max(I,background); ID=ID>.5; %5. NOISE. %add binary noise to BW image errorb=0; bin_noise_create pause close load Noise 'binary noise level=' errorb ID=addbin(ID,errorb/100); %6. DISPLAY. %display I and ID subplot(1,2,1), see(I) title('image I') axis('image') subplot(1,2,2),see(ID) title('observed image ID'); axis('image') %auxiliary functions: function fig = select_t() load select_t h0 = figure('Color',[0.8 0.8 0.8], ... 'Colormap',mat0, ... 'PointerShapeCData',mat1, ... 'Position',[364 111 560 420], ... 'Tag','Fig1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[70.5 189.75 295.5 99], ... 'String','Select one object type (template generator) by pushing the relevant button', ... 'Style','text', ... 'Tag','StaticText1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'Callback','val1=get(gco,''Value'');save types val1', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[16.5 62.25 33.75 24], ... 'String','1', ... 'Tag','Pushbutton1', ... 'Value',1); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'Callback','val2=get(gco,''Value'');save types val2', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[88.875 61.875 31.5 25.5], ... 'String','2', ... 'Tag','Pushbutton2', ... 'Value',1); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'Callback','val5=get(gco,''Value'');save types val5', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[310.5 61.5 33 24.75], ... 'String','5', ... 'Tag','Pushbutton3'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'ButtonDownFcn','4', ... 'Callback','val4=get(gco,''Value'');save types val4', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[231.75 62.25 39.75 23.25], ... 'String','4', ... 'Tag','Pushbutton4'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'Callback','val3=get(gco,''Value'');save types val3', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[159 62.25 34.5 24], ... 'String','3', ... 'Tag','Pushbutton5'); if nargout > 0, fig = h0; end function result=fastint(I,s1,s2) %interpolates (bilinearly) matrix I given at equally spaced grid points %to points displaced by vector field s with components s1 and s2 [l1,l2]=size(I); [Y,X]=meshgrid(1:l2,(1:l1)'); XI=X+s1;M=XI>l1.*ones(l1,l2);XI=(1-M).*XI+M.*l1.*ones(l1,l2); M=XIl2.*ones(l1,l2);YI=(1-M).*YI+M.*l2.*ones(l1,l2); M=YI 0, fig = h0; end function JD=addbin(J,errorprob) %computes deformed image JD by adding binary noise to %BW image J; addition modulo 2 [l1,l2]=size(J); errors=rand(l1,l2) 0, fig = h0; end function fig = def_create() load def_create h0 = figure('Color',[0.8 0.8 0.8], ... 'Colormap',mat0, ... 'PointerShapeCData',mat1, ... 'Position',[120 120 560 420], ... 'Tag','Fig1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','Select deformation level applied to template', ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[54 250.5 325.5 43.5], ... 'String','Select deformation level applied to template', ... 'Style','text', ... 'Tag','StaticText1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','deflevel=get(gco,''Value'');save Noise deflevel', ... 'ListboxTop',0, ... 'Position',[55.5 138 312 27], ... 'Style','slider', ... 'Tag','Slider1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'ButtonDownFcn','0', ... 'FontSize',12, ... 'ListboxTop',0, ... 'Position',[59.25 166.5 19.5 14.25], ... 'String','0', ... 'Style','text', ... 'Tag','StaticText2'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',12, ... 'ListboxTop',0, ... 'Position',[354.75 167.25 14.25 15.75], ... 'String','1', ... 'Style','text', ... 'Tag','StaticText3'); if nargout > 0, fig = h0; end function fig = select_Euclid() load select_Euclid h0 = figure('Color',[0.8 0.8 0.8], ... 'Colormap',mat0, ... 'PointerShapeCData',mat1, ... 'Position',[221 135 560 420], ... 'Tag','Fig1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback',mat2, ... 'FontSize',22, ... 'ListboxTop',0, ... 'Position',[24 231.75 367.5 69], ... 'String',mat3, ... 'Style','text', ... 'Tag','StaticText1'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','DY=get(gco,''Value'');save Euclid DY', ... 'ListboxTop',0, ... 'Max',20, ... 'Min',-20, ... 'Position',[262.5 54.75 18.75 161.25], ... 'Style','slider', ... 'Tag','Slider1', ... 'Value',3); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','DX=get(gco,''Value''); save Euclid DX', ... 'ListboxTop',0, ... 'Max',20, ... 'Min',-20, ... 'Position',[81.75 57.75 17.25 158.25], ... 'Style','slider', ... 'Tag','Slider2'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','ROT=get(gco,''Value'');save Euclid ROT', ... 'ListboxTop',0, ... 'Max',90, ... 'Min',-90, ... 'Position',[87.75 10.5 195.75 15], ... 'String','6.3', ... 'Style','slider', ... 'Tag','Slider3', ... 'Value',-29.16); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',11, ... 'ListboxTop',0, ... 'Position',[117.75 134.25 18 12.75], ... 'String','DX', ... 'Style','text', ... 'Tag','StaticText2'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',11, ... 'ListboxTop',0, ... 'Position',[309 132 18.75 15], ... 'String','DY', ... 'Style','text', ... 'Tag','StaticText3'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',11, ... 'ListboxTop',0, ... 'Position',[170.25 38.25 30 12.75], ... 'String','ROT', ... 'Style','text', ... 'Tag','StaticText4'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'ListboxTop',0, ... 'Max',30, ... 'Min',-30, ... 'Position',[289.5 77.25 20.25 19.5], ... 'String','20', ... 'Style','text', ... 'Tag','StaticText5'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'Callback','30', ... 'FontSize',11, ... 'ListboxTop',0, ... 'Position',[287.25 191.25 21 15], ... 'String','20', ... 'Style','text', ... 'Tag','StaticText6'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',11, ... 'ListboxTop',0, ... 'Max',30, ... 'Min',-30, ... 'Position',[58.5 81.75 17.25 14.25], ... 'String','-20', ... 'Style','text', ... 'Tag','StaticText7'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'FontSize',11, ... 'ListboxTop',0, ... 'Position',[54.75 187.5 21 13.5], ... 'String','20', ... 'Style','text', ... 'Tag','StaticText8'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'ListboxTop',0, ... 'Position',[59.25 11.25 21.75 13.5], ... 'String','-90', ... 'Style','text', ... 'Tag','StaticText9'); h1 = uicontrol('Parent',h0, ... 'Units','points', ... 'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ... 'ListboxTop',0, ... 'Position',[290.25 9 24.75 15], ... 'String','90', ... 'Style','text', ... 'Tag','StaticText10'); if nargout > 0, fig = h0; end function see(I) %displays normalized image z=I-min(min(I));z=z./max(max(z)); image(30.*z)