www.pudn.com > snippets(1).rar > features.m, change:2009-10-15,size:2876b


function features(experiment_name)

% parameters for image preprocessing
Globals.image_scale = 1;

% Gabor filter bank parameters
Globals.gabor_numscale = 4;
Globals.gabor_numdir =  6;
Globals.gabor_minsize = 2;

% parameters for flow filtering
Globals.flow_numvel = 2;
Globals.flow_velocityzero = true;
Globals.flow_numdir = 4;
Globals.flow_scales = [8 16]; % [6 12];

% parameters for low-level optic-flow algorithm
Globals.flow_useSSD = false;
Globals.flow_smooth = false;

% parameters for file I/O
Globals.extension = 'png';
Globals.nameL = 'L.v1.mat';
Globals.nameR = 'R.v1.mat';

addpath ./filters/

% get started: read input file
fid = fopen(experiment_name,'r');
if fid<0
  error('READ_EXP: cannot open file');
end
content = textscan(fid,'%s%d');
fclose(fid);

filelist = content{1};
numbers  = content{2};

% loop through input sequences
for u = 1:length(filelist)

  fprintf('Processing line %d / %d ... ',u,length(filelist));

  % keyword, not data in this line
  if strcmp(filelist{u}, 'frames')
    numframes = numbers(u);
    fprintf('start parsing - %d FRAMES PER SEQUENCE\n',numframes);
    continue;
  end

  if strcmp(filelist{u}, 'subject')
    fprintf('starting NEW SUBJECT\n');
    continue;
  end

  % read image sequence and preprocess
  for v = 1:numframes

    f = imread([filelist{u} sprintf('.%.3d.',v)  Globals.extension]);
    if size(f,3)>1
      f = rgb2gray(f);
    end
    f = single(f);
    if Globals.image_scale~=1
      f = imresize(f,Globals.image_scale,'bicubic');
    end

    I(:,:,v) = f;

  end % for v

  % compute flow features
  fprintf('optic flow ... ');
  flow = extract_flowfeatures(I,Globals);

  % compute form features
  fprintf('local edges ... ');
  form = cell(Globals.gabor_numscale,Globals.gabor_numdir,1);

  for v = 1:numframes-1

    hlp = gaborconvolve(I(:,:,v+1), ...
			Globals.gabor_numscale, ...
			Globals.gabor_numdir, ...
			Globals.gabor_minsize, ...
			2,0.65,1.5,0);
    hlp = magnitude(hlp);

    for a = 1:Globals.gabor_numscale
      for b = 1:Globals.gabor_numdir

	form{a,b,1}(:,:,v) = single((hlp{a,b}));

      end
    end

  end

  % write to file
  fprintf('save to disk ... ');
  sl = length(filelist{u});
  outname = [filelist{u} '.' Globals.nameL];
  save(outname,'flow','form');

  % mirror along vertical axis
  [A,B,C] = size(flow);
  D = size(flow{1,1,1},3);
  for a = 1:A % loop over directions
    for b = 1:B % loop over velocities
      for c = 1:C % loop over scales
	for d = 1:D % loop over frames
	  flow{a,b,c}(:,:,d) = fliplr(flow{a,b,c}(:,:,d));
	end
      end
    end
  end

  for a = 1:Globals.gabor_numscale
    for b = 1:Globals.gabor_numdir
      for c = 1:D
	form{a,b,1}(:,:,c) = fliplr(form{a,b,1}(:,:,c));
      end
    end
  end

  % write mirrored to file
  outname = [filelist{u} '.' Globals.nameR];
  save(outname,'flow','form');

  fprintf('DONE\n');

end % for u