% DIGIFILTER_circ 

% === PREPARE VARIABLES ===
b=1; j=0;
X=[]; CT=[]; RA=[];
t=linspace(0,2*pi,32);
co=cos(t); si=sin(t);

% === MESSAGE ===
hat=text(0,-20,'Press <ESC> to finish series.','Fontsize',14,'Color','b');

% === DIGITIZE ===
while b<27   
   [x,y,b]=ginput(1);
    if b==3, 
      plot([X(j-1:j,1)],[X(j-1:j,2)],'k');
      plot([X(j,1)],[X(j,2)],'.k');
      j=j-1;
    end
    if b==1,
      j=j+1;
      CT(j,:)=[x y]; 
      plot([x],[y],'.b');
      [x,y,b]=ginput(1);
      r=sqrt((x-CT(j,1))^2 + (y-CT(j,2))^2);
      plot(CT(j,1)+r*co,CT(j,2)+r*si,'r')
      RA(j)=r;
    end
    if (b==99)|(b==67),
        
    end   
end
 J=j;
 
[Ny,Nx]=size(At);
[x,y]=meshgrid(1:Nx,1:Ny);

for j=1:J
MASK=MASK + inpolygon(x,y,CT(j,1)+RA(j)*co,CT(j,2)+RA(j)*si);
end

% === DISPLAY ===
MASK=min(MASK,1);
MAC(:,:,1)=MASK;

image(uint8(FTC*220 +35*MAC) );
SHOW=1;
set(HHHL.buttonTOGGLEFILTER,'String','SHOW FILTER');

delete(hat);
