function N_features=cp_qmf(x,FeatureFN,NonlinId,SmoothId,NormId,FeatDec,FilterId,Structure,DoDecFB)
% CP_QMF  Comparative texture measure study: QMF features
%	N_features=cp_qmf(x,FeatureFN,NonlinId,SmoothId,NormId,...
%	  FeatDec,FilterId,Structure,DoDecFB)

ImageFile=tempnam;
TmpFN=tempnam;
[M,N]=size(x);
dM=2^ceil(log2(M))-M;
dN=2^ceil(log2(N))-N;
x=symmext(x,0,dM,0,dN);

% Write image
hipswrite(x,ImageFile);

% Feature extraction
if idcmp(FilterId,'Gabor')
  eval(sprintf('!mcf -sn %d -nnl -navg %s > %s',...
    Structure,ImageFile,FeatureFN));
else
  if DoDecFB % 				Decimation of filter bank
    eval(sprintf('!qmf -d -analysis -f %s -sn %d %s > %s',...
      FilterId,Structure,ImageFile,FeatureFN));
  else % 				No decimation of filter bank
    eval(sprintf('!qmf -analysis -f %s -sn %d %s > %s',...
      FilterId,Structure,ImageFile,FeatureFN));
  end
end
N_features=hsize(FeatureFN,'Frames');
cp_energy([],NonlinId,SmoothId,NormId,[],Structure,DoDecFB,...
  FeatureFN,FeatDec);
if dM>0 | dN>0
  eval(sprintf('!extract -p 0 0 -s %d %d %s > %s',...
    M/FeatDec,N/FeatDec,FeatureFN,TmpFN));
  eval(sprintf('!mv %s %s',TmpFN,FeatureFN));
end

% Clean
eval(sprintf('!rm -f %s %s',TmpFN,ImageFile));



