function varargout = imgxtool(option,varargin)
%IMGXTOOL Image extension tool.
% VARARGOUT = IMGXTOOL(OPTION,VARARGIN)
%
% GUI oriented tool which allows the construction of a new
% image from an original one by truncation or extension.
% Extension is done by selecting different possible modes:
% Symmetric, Periodic, Zero Padding, Continuous or Smooth.
% A special mode is provided to extend an image in order
% to be accepted by the SWT decomposition.
%------------------------------------------------------------
% Internal options:
%
% OPTION = 'create' 'load' 'demo'
% 'update_deslen' 'extend_truncate'
% 'draw' 'save'
% 'clear_graphics' 'mode'
% 'close'
%
% See also WEXTEND.
% M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 30-Nov-98.
% Last Revision: 14-Jul-2003.
% Copyright 1995-2004 The MathWorks, Inc.
% $Revision: 1.12.4.2 $ $Date: 2004/03/15 22:40:45 $
% Test inputs.
%-------------
if nargin==0 , option = 'create'; end
[option,winAttrb] = utguidiv('ini',option,varargin{:});
% Default values.
%----------------
default_nbcolors = 255;
% Image Coding Value.
%-------------------
codemat_v = wimgcode('get');
% Initialisations for all options excepted 'create'.
%---------------------------------------------------
switch option
case 'create'
otherwise
% Get figure handle.
%-------------------
win_imgxtool = varargin{1};
% Get stored structure.
%----------------------
Hdls_UIC_C = wfigmngr('getValue',win_imgxtool,'Hdls_UIC_C');
Hdls_UIC_H = wfigmngr('getValue',win_imgxtool,'Hdls_UIC_H');
Hdls_UIC_V = wfigmngr('getValue',win_imgxtool,'Hdls_UIC_V');
Hdls_UIC_Swt = wfigmngr('getValue',win_imgxtool,'Hdls_UIC_Swt');
Hdls_Axes = wfigmngr('getValue',win_imgxtool,'Hdls_Axes');
Hdls_Colmap = wfigmngr('getValue',win_imgxtool,'Hdls_Colmap');
Pos_Axe_Img_Ori = wfigmngr('getValue',win_imgxtool,'Pos_Axe_Img_Ori');
% Get UIC Handles.
%-----------------
[m_load,m_save,m_demo,txt_image,edi_image,...
txt_mode,pop_mode,pus_extend] = deal(Hdls_UIC_C{:});
[frm_fra_H,txt_fra_H,txt_length_H,edi_length_H,txt_nextpow2_H, ...
edi_nextpow2_H,txt_prevpow2_H,edi_prevpow2_H,txt_deslen_H, ...
edi_deslen_H,txt_direct_H,pop_direct_H] = deal(Hdls_UIC_H{:});
[frm_fra_V,txt_fra_V,txt_length_V,edi_length_V,txt_nextpow2_V, ...
edi_nextpow2_V,txt_prevpow2_V,edi_prevpow2_V,txt_deslen_V, ...
edi_deslen_V,txt_direct_V,pop_direct_V] = deal(Hdls_UIC_V{:});
[txt_swtdec,pop_swtdec,frm_fra_H_2,txt_fra_H_2,txt_swtlen_H, ...
edi_swtlen_H,txt_swtclen_H,edi_swtclen_H,txt_swtdir_H, ...
edi_swtdir_H,txt_swtdec,pop_swtdec,frm_fra_V_2,txt_fra_V_2, ...
txt_swtlen_V,edi_swtlen_V,txt_swtclen_V,edi_swtclen_V, ...
txt_swtdir_V,edi_swtdir_V] = deal(Hdls_UIC_Swt{:});
end
% Process control depending on the calling option.
%-------------------------------------------------
switch option
case 'create'
%-------------------------------------------------------%
% Option: 'CREATE' - Create Figure, Uicontrols and Axes %
%-------------------------------------------------------%
% Get Globals.
%-------------
[Def_Btn_Height,Def_Btn_Width,Pop_Min_Width,X_Graph_Ratio, ...
X_Spacing,Y_Spacing,Def_TxtBkColor,Def_EdiBkColor, ...
Def_FraBkColor] = ...
mextglob('get', ...
'Def_Btn_Height','Def_Btn_Width','Pop_Min_Width', ...
'X_Graph_Ratio','X_Spacing','Y_Spacing', ...
'Def_TxtBkColor','Def_EdiBkColor','Def_FraBkColor' ...
);
% Window initialization.
%-----------------------
[win_imgxtool,pos_win,win_units,str_numwin, ...
frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
wfigmngr('create','Image Extension / Truncation', ...
winAttrb,'ExtFig_Tool_3', ...
strvcat(mfilename,'cond'),1,1,0);
if nargout>0 , varargout{1} = win_imgxtool; end
% Add Help for Tool.
%------------------
wfighelp('addHelpTool',win_imgxtool, ...
'Two-Dimensional &Extension','IMGX_GUI');
% Add Help Item.
%----------------
wfighelp('addHelpItem',win_imgxtool,...
'Dealing with Border Distortion','BORDER_DIST');
% Menu construction for current figure.
%--------------------------------------
m_files = wfigmngr('getmenus',win_imgxtool,'file');
m_load = uimenu(m_files, ...
'Label','&Load Image', ...
'Position',1, ...
'Callback', ...
[mfilename '(''load'',' str_numwin ');'] ...
);
m_save = uimenu(m_files,...
'Label','&Save Transformed Image', ...
'Position',2, ...
'Enable','Off', ...
'Callback', ...
[mfilename '(''save'',' str_numwin ');'] ...
);
m_demo = uimenu(m_files, ...
'Label','&Example Extension','Position',3);
demoSET = {...
'woman2' , 'ext' , '{''zpd'' , [220,200] , ''both'' , ''both''}' ; ...
'woman2' , 'trunc' , '{''nul'' , [ 96, 96] , ''both'' , ''both''}' ; ...
'wbarb' , 'ext' , '{''sym'' , [512,200] , ''right'', ''both''}' ; ...
'noiswom' , 'ext' , '{''sym'' , [512,512] , ''right'', ''down''}' ; ...
'noiswom' , 'ext' , '{''ppd'' , [512,512] , ''right'', ''down''}' ; ...
'wbarb' , 'ext' , '{''sym'' , [512,512] , ''both'' , ''both''}' ; ...
'facets' , 'ext' , '{''ppd'' , [512,512] , ''both'' , ''both''}' ; ...
'mandel' , 'ext' , '{''sym'' , [512,512] , ''left'' , ''both''}' ...
};
nbDEM = size(demoSET,1);
beg_call_str = [mfilename '(''demo'',' str_numwin ','''];
dummy = demoSET(:,1);
names = strvcat(dummy{:});
tab = setstr(9);
for k = 1:nbDEM
typ = demoSET{k,2};
fil = demoSET{k,1};
par = demoSET{k,3};
parVal = eval(par);
switch parVal{1}
case 'swt'
lenSTR = [' - level: ',int2str(parVal{2})];
otherwise
siz = fliplr(parVal{2});
lenSTR = [' - size: [' , int2str(parVal{2}) , ']'];
end
strPAR = ['mode: ' , parVal{1} , lenSTR, ...
' - direction: [', parVal{3} , ',' parVal{4} ,']'];
switch typ
case 'ext' , strTYPE = ['Extension - '];
case 'trunc' , strTYPE = ['Truncation - '];
end
libel = [names(k,:) tab ' - ' strTYPE strPAR];
action = [beg_call_str fil ''',''' typ ''',' par ');'];
uimenu(m_demo,'Label',libel,'Callback',action);
end
% Begin waiting.
%---------------
wwaiting('msg',win_imgxtool,'Wait ... initialization');
% Borders and double borders.
%----------------------------
dx = X_Spacing; dx2 = 2*dx;
dy = Y_Spacing; dy2 = 2*dy;
% General graphical parameters initialization.
%--------------------------------------------
x_frame0 = pos_frame0(1);