%kitexture 'Texture Feature Extraction Using LAW Metrics'
% This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros itexture.pane file
%
% Parameters: 
% InputFile: i 'Input object ', required: 'input object'
% OutputFile: o 'Output object', required: 'output object'
% Toggle: L5L5 'L5L5', default: 0: 'If set, apply L5L5 texture kernel'
% Toggle: E5L5 'E5L5', default: 0: 'If set, apply E5L5 texture kernel'
% Toggle: S5L5 'S5L5', default: 0: 'If set, apply S5L5 texture kernel'
% Toggle: W5L5 'W5L5', default: 0: 'If set, apply W5L5 texture kernel'
% Toggle: R5L5 'R5L5', default: 0: 'If set, apply R5L5 texture kernel'
% Toggle: L5E5 'L5E5', default: 0: 'If set, apply L5E5 texture kernel'
% Toggle: E5E5 'E5E5', default: 0: 'If set, apply E5E5 texture kernel'
% Toggle: S5E5 'S5E5', default: 0: 'If set, apply S5E5 texture kernel'
% Toggle: W5E5 'W5E5', default: 0: 'If set, apply W5E5 texture kernel'
% Toggle: R5E5 'R5E5', default: 0: 'If set, apply R5E5 texture kernel'
% Toggle: L5S5 'L5S5', default: 0: 'If set, apply L5S5 texture kernel'
% Toggle: E5S5 'E5S5', default: 0: 'If set, apply E5S5 texture kernel'
% Toggle: S5S5 'S5S5', default: 0: 'If set, apply S5S5 texture kernel'
% Toggle: W5S5 'W5S5', default: 0: 'If set, apply W5S5 texture kernel'
% Toggle: R5S5 'R5S5', default: 0: 'If set, apply R5S5 texture kernel'
% Toggle: L5W5 'L5W5', default: 0: 'If set, apply L5W5 texture kernel'
% Toggle: E5W5 'E5W5', default: 0: 'If set, apply E5W5 texture kernel'
% Toggle: S5W5 'S5W5', default: 0: 'If set, apply S5W5 texture kernel'
% Toggle: W5W5 'W5W5', default: 0: 'If set, apply W5W5 texture kernel'
% Toggle: R5W5 'R5W5', default: 0: 'If set, apply R5W5 texture kernel'
% Toggle: L5R5 'L5R5', default: 0: 'If set, apply L5R5 texture kernel'
% Toggle: E5R5 'E5R5', default: 0: 'If set, apply E5R5 texture kernel'
% Toggle: S5R5 'S5R5', default: 0: 'If set, apply S5R5 texture kernel'
% Toggle: W5R5 'W5R5', default: 0: 'If set, apply W5R5 texture kernel'
% Toggle: R5R5 'R5R5', default: 0: 'If set, apply R5R5 texture kernel'
%
% Example: o = kitexture(i, {'i','';'o','';'L5L5',0;'E5L5',0;'S5L5',0;'W5L5',0;'R5L5',0;'L5E5',0;'E5E5',0;'S5E5',0;'W5E5',0;'R5E5',0;'L5S5',0;'E5S5',0;'S5S5',0;'W5S5',0;'R5S5',0;'L5W5',0;'E5W5',0;'S5W5',0;'W5W5',0;'R5W5',0;'L5R5',0;'E5R5',0;'S5R5',0;'W5R5',0;'R5R5',0})
%
% Khoros helpfile follows below:
%
%  PROGRAM
% itexture - Texture Feature Extraction Using LAW Metrics
%
%  DESCRIPTION
% .I itexture
% will extract texture features from an image by convolving the original image 
% with a set of special spatial filter kernels.  The spatial filters are 
% comprised of 5 x 5 kernels 
% derived from center-weighted vectors defined by the LAWS texture measure.
% 
% Each texture measure calculated will be stored as width-height planes along 
% the elements direction in the Output Object (o).  
% The order in which the (selected) texture measures will be stored in the 
% output object are:
% .DS
%         L5L5
%         L5E5
%         L5S5
%         L5W5
%         L5R5
%         E5L5
%         E5E5
%         E5S5
%         E5W5
%         E5R5
%         S5L5
%         S5E5
%         S5S5
%         S5W5
%         S5R5
%         W5L5
%         W5E5
%         W5S5
%         W5W5
%         W5R5
%         R5L5
%         R5E5
%         R5S5
%         R5W5
%         R5R5
% .DE
% 
% If the input object elements dimension is greater than 1 then the results 
% obtained by applying the first selected kernel to each band are stored by planes
% in the output object, followed by the results obtained by applying the
% next selected texture kernel to all bands, and so on. Thus a 3-band input
% image, operated on by the L5L5 and R5R5 kernels, will produce a 6-band
% output image with the results as follows:
% .DS
%       Band 0 - L5L5 on Band 0 of input image
%       Band 1 - L5L5 on Band 1 of input image
%       Band 2 - L5L5 on Band 2 of input image
%       Band 3 - R5R5 on Band 0 of input image
%       Band 4 - R5R5 on Band 1 of input image
%       Band 5 - R5R5 on Band 2 of input image
% .DE
% 
% The five center-weighted vectors are:
% .DS
%          L5 = [ 1  4  6  4  1]
%          E5 = [-1 -2  0  2  1]
%          S5 = [-1  0  2  0 -1]
%          W5 = [-1  2  0 -2  1]
%          R5 = [ 1 -4  6 -4  1]
% .DE
% 
% Each 5 x 5 kernel is derived from multiplying a particular combination of
% two of the above vectors.  This results in 25 possible 5 x 5 kernels.
% Note that 10 of the kernels are formed by taking the transpose.  For example,
% L5E5 is a 5 x 5 kernel formed by multiplying the vectors, L5 with E5.  It's
% transpose is E5L5, and is similarly formed by multiplying the vectors,
% E5 with L5.  One of these kernels is more sensitive to horizontal 
% changes in texture, while the other is sensitive to vertical changes in
% texture. 
% 
% The kernels are applied with a centered hotspot.
% 
% The sum of the elements of each kernel is zero, which results in the output 
% image having a mean of zero.  Therefore the relevant texture information is
% contained in the image variance of the microtexture features.  The LAW 
% kernels were designed to be sensitive to structures such as edges, ripples, 
% and spots.
% 
% Choosing which kernel to use will depend on the nature of the texture of
% interest, and will require trial and error to decide which produces the
% feature with the most discriminating power.  In general, if a texture kernel
% of say, L5S5 is used, one may also want to use its transpose, S5L5 for
% certain types of quasiperiodic variations commonly found in textured images.
% 
% The colorspace model for the output object is always set to KNONE.
%
%  
%
%  EXAMPLES
%
%  "SEE ALSO"
%
%  RESTRICTIONS 
% .I itexture
% will operate on input objects of any data storage type.
% 
% The output object will be of type KLONG, KDOUBLE, or
% KDCOMPLEX, determined by the data type of the input object.
% If the input object is of data type KBYTE, KUBYTE, KSHORT, or KUSHORT,
% then it is converted up to an KLONG image. If the input
% is of type KFLOAT or KDOUBLE, then the result will be KDOUBLE.
% Any complex input type is converted to type KDCOMPLEX.
%
%  REFERENCES 
% K. I. Laws, "Rapid texture identification" Proc. SPIE, vol. 238, pp.376-380,
% 1980.
% 
% J. Y. Hsiao, and A. A. Sawchuk, "Supervised textured image segmentation
% using feature smoothing and probabilistic relaxation techniques" IEEE Trans.
% Pattern Anal. Machine Intell., vol. 11, No. 12, pp 1279-1292, 1989.
%
%  COPYRIGHT
% Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI")  All rights reserved.
% 


function varargout = kitexture(varargin)
if nargin ==0
  Inputs={};arglist={'',''};
elseif nargin ==1
  Inputs=varargin{1};arglist={'',''};
elseif nargin ==2
  Inputs=varargin{1}; arglist=varargin{2};
else error('Usage: [out1,..] = kitexture(Inputs,arglist).');
end
if size(arglist,2)~=2
  error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
 end
narglist={'i', '__input';'o', '__output';'L5L5', 0;'E5L5', 0;'S5L5', 0;'W5L5', 0;'R5L5', 0;'L5E5', 0;'E5E5', 0;'S5E5', 0;'W5E5', 0;'R5E5', 0;'L5S5', 0;'E5S5', 0;'S5S5', 0;'W5S5', 0;'R5S5', 0;'L5W5', 0;'E5W5', 0;'S5W5', 0;'W5W5', 0;'R5W5', 0;'L5R5', 0;'E5R5', 0;'S5R5', 0;'W5R5', 0;'R5R5', 0};
maxval={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
minval={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
istoggle=[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
was_set=istoggle * 0;
paramtype={'InputFile','OutputFile','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle'};
% identify the input arrays and assign them to the arguments as stated by the user
if ~iscell(Inputs)
Inputs = {Inputs};
end
NumReqOutputs=1; nextinput=1; nextoutput=1;
  for ii=1:size(arglist,1)
  wasmatched=0;
  for jj=1:size(narglist,1)
   if strcmp(arglist{ii,1},narglist{jj,1})  % a given argument was matched to the possible arguments
     wasmatched = 1;
     was_set(jj) = 1;
     if strcmp(narglist{jj,2}, '__input')
      if (nextinput > length(Inputs)) 
        error(['Input ' narglist{jj,1} ' has no corresponding input!']); 
      end
      narglist{jj,2} = 'OK_in';
      nextinput = nextinput + 1;
     elseif strcmp(narglist{jj,2}, '__output')
      if (nextoutput > nargout) 
        error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']); 
      end
      if (isempty(arglist{ii,2}))
        narglist{jj,2} = 'OK_out';
      else
        narglist{jj,2} = arglist{ii,2};
      end

      nextoutput = nextoutput + 1;
      if (minval{jj} == 0)  
         NumReqOutputs = NumReqOutputs - 1;
      end
     elseif isstr(arglist{ii,2})
      narglist{jj,2} = arglist{ii,2};
     else
        if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
            error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
        end
        if (minval{jj} ~= 0 | maxval{jj} ~= 0)
          if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
            error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
          elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
            error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
          elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
            error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
          elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
            error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
            error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
            error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
          end
        end
     end
     if ~strcmp(narglist{jj,2},'OK_out') &  ~strcmp(narglist{jj,2},'OK_in') 
       narglist{jj,2} = arglist{ii,2};
     end
   end
   end
   if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
        error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
   end
end
% match the remaining inputs/outputs to the unused arguments and test for missing required inputs
 for jj=1:size(narglist,1)
     if  strcmp(paramtype{jj}, 'Toggle')
        if (narglist{jj,2} ==0)
          narglist{jj,1} = ''; 
        end;
        narglist{jj,2} = ''; 
     end;
     if  ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
          narglist{jj,1} = ''; 
          narglist{jj,2} = ''; 
     end;
     if strcmp(narglist{jj,2}, '__input')
      if (minval{jj} == 0)  % meaning this input is required
        if (nextinput > size(Inputs)) 
           error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']); 
        else
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        end
      else  % this is an optional input
        if (nextinput <= length(Inputs)) 
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        else 
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end;
     else 
     if strcmp(narglist{jj,2}, '__output')
      if (minval{jj} == 0) % this is a required output
        if (nextoutput > nargout & nargout > 1) 
           error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']); 
        else
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
          NumReqOutputs = NumReqOutputs-1;
        end
      else % this is an optional output
        if (nargout - nextoutput >= NumReqOutputs) 
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
        else 
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end
     end
  end
end
if nargout
   varargout = cell(1,nargout);
else
  varargout = cell(1,1);
end
global KhorosRoot
if exist('KhorosRoot') && ~isempty(KhorosRoot)
w=['"' KhorosRoot];
else
if ispc
  w='"C:\Program Files\dip\khorosBin\';
else
[s,w] = system('which cantata');
w=['"' w(1:end-8)];
end
end
[varargout{:}]=callKhoros([w 'itexture"  '],Inputs,narglist);
