% DIGIFILTER
%  INPUT:   At = Fourier Transform of image
%  OUTPUT:  MASK = The designed filter

% === FIGURE FOR FILTER ===


% === SHOW At AS A FOURIER TRANSFORM ===
fig=100;   % fig for FT
figure(fig); clf
IPgreymap(256);
FTS=fftshift(log(abs(At)+1))/(IPmax(log(abs(At)+1)));
clear FTC MAC MASK
for j=1:3, FTC(:,:,j)=FTS; end
image(uint8(FTC*220));
axis image
hold on
hax=gca;
titl=text(0,-60,'DIGIFILTER: App for designing a filter.','Fontsize',16,'Color','k');


% === PREPARE VARIABLES ~ GENERAL ===
[Ny,Nx]=size(At);
[x,y]=meshgrid(1:Nx,1:Ny);
MASK=logical(0*At);

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

% === PLACE GUI WIDGETS ===

HHHL.buttonTOGGLEFILTER=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','SHOW FILTER',...
       'Callback','DIGIFILTER_showtoggle',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[110 70 100 20]); 

HHHL.buttonCLEARFILTER=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','CLEAR FILTER',...
       'Callback','DIGIFILTER_clear',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[110 40 100 20]); 
   
HHHL.buttonINVERTFILTER=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','INVERT FILTER',...
       'Callback','DIGIFILTER_invert',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[110 10 100 20]); 
   

HHHL.buttonCIRC=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','CIRC VAR-RADIUS',...
       'Callback','DIGIFILTER_circ',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[220 40 100 20]); 
   
HHHL.buttonCIRCR=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','CIRC FIXED-RADIUS',...
       'Callback','DIGIFILTER_circR',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[220 10 100 20]);    

HHHL.buttonPATCH=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','POLYGON PATCH',...
       'Callback','DIGIFILTER_patch',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[330 10 100 20]); 
   
HHHL.buttonSYM=uicontrol(...
       'Units','pixels',...
       'Style','pushbutton',...
       'String','SYMMETRIZE',...
       'Callback','DIGIFILTER_sym',...
       'BackgroundColor',[1 1 1]*0.8,...
       'Position',[440 10 100 20]); 
   
HHHL.textINST1=uicontrol(...
       'Units','pixels',...
       'Style','text',...
       'String','INPUT: FT in matrix At',...
       'HorizontalAlignment','left',...
       'Fontsize',12,...
       'Position',[460 80 300 20]); 
   
HHHL.textINST2=uicontrol(...
       'Units','pixels',...
       'Style','text',...
       'String','OUTPUT: Filter in matrix MASK',...
       'HorizontalAlignment','left',...
       'Fontsize',12,...
       'Position',[460 60 300 20]);    


