function N_features=cp_eigen(x,FeatureFN,ImageId,NonlinId,SmoothId,NormId,FeatDec)
% CP_EIGEN  Comparative texture measure study: Eigenfilter features
%	N_features=cp_eigen(x,FeatureFN,ImageId,...
%	  NonlinId,SmoothId,NormId,FeatDec)

% Initialization
N_features=0;
if strcmp(lower(SmoothId),'gauss')
  f_0=2.^(-5)*sqrt(2);
elseif strcmp(lower(SmoothId),'average')
  M_w=31;
  N_w=31;
  f_0=[M_w N_w];
else
  error(fprintf('Smoothing option "%s" not supported',SmoothId));
end
M_h=3;
N_h=3;

[x_i,N_tex]=cp_image(ImageId,1); % 	Determine number of textures
for TexNo=1:N_tex
  fprintf(1,':');
  % Filter design
  [x_i,N_tex,r_xxi]=cp_image(ImageId,TexNo);
  R_xxi=r2R(r_xxi,M_h,N_h);
  [V,D]=eig(R_xxi);
  D=diag(D);
  efn=0;
  while sum(D(1:efn))<0.99*sum(D) & efn*N_tex<=40
    fprintf(1,'.');
    efn=efn+1;
    h_=V(:,efn); 
    h=reshape(h_,N_h,M_h).';
    % Filtering
    y=filter2(h,x);
    % Local energy function
    z=cp_energy(y,NonlinId,SmoothId,NormId,f_0);
    % Write feature file
    catframe(z,FeatureFN,[],'Interm',FeatDec);
  end
  N_features=N_features+efn;
end


  




