gusucode.com > Matlab脸部识别程序源码 > code/code/extract_features.m
function [features] = extract_features(image,numrect,plotflag) % [featues] = extract_features(image,numrect,plotflag) % % Nathan Sutter, Fall 2007 % Last Updated, 11/14/07 %-------------------------------------------------------------------------- % Inputs: %-------------------------------------------------------------------------- % image : MxNx matrix, where MxN is the image size. We assume here % that the images are black and white % % numrect : Index for the feature extraction type you'd like to do. % 1 : Vertical Stacking of two boxes % 2 : Horizontal Stacking of two boxes % % plotflag : If 1, will go through and plot the boxes on top of the % image that are being computed. Good for visualizing the % feature extraction process. %-------------------------------------------------------------------------- % Outputs: %-------------------------------------------------------------------------- % features : The computed scalar features stacked in a numfeaturesx1 % vector %-------------------------------------------------------------------------- totalfeatures = 1; [rows cols numimages] = size(image); %I need to precalculate this features = zeros(43200*numimages,1); testimage_orig = image; %image(:,:,f);%imread('face.jpg'); testimage = testimage_orig; [rows cols dim] = size(testimage); numsteps = dim*dim; %only works for the 1x1 rectangles ii = integral_image(testimage_orig); %features = zeros(numsteps,1); for s=1 :rows for w=1:(rows/2) %assumes dim is even, and more formally, that dim is 24. step = 1; %w r1_start_row = zeros(numsteps,1); r1_start_col = zeros(numsteps,1); r2_start_row = zeros(numsteps,1); r2_start_col = zeros(numsteps,1); r1_end_row = zeros(numsteps,1); r1_end_col = zeros(numsteps,1); r2_end_row = zeros(numsteps,1); r2_end_col = zeros(numsteps,1); r1_start_row(1) = 1; r1_end_row(1) = s; r1_start_col(1) = 1; r1_end_col(1) = w; r2_start_row(1) = 1; r2_end_row(1) = s; r2_start_col(1) = r1_end_col(1)+1; r2_end_col(1) = r1_end_col(1)+1+(w-1); for j=1:rows - (s-1) for i=1:cols-1 - (w*2 - 2) if plotflag rgbimage = gray2ind(testimage,256); rgbimage = ind2rgb(rgbimage,gray(256)); rgbimage(r1_start_row(step):r1_end_row(step),r1_start_col(step):r1_end_col(step),1) = .99; rgbimage(r2_start_row(step):r2_end_row(step),r2_start_col(step):r2_end_col(step),3) = .99; image(rgbimage); pause(.005); testimage = testimage_orig; end if numrect == 1 rectA_ii = rect_sum(ii,r1_start_row(step),r1_start_col(step),r1_end_row(step),r1_end_col(step)); rectB_ii = rect_sum(ii,r2_start_row(step),r2_start_col(step),r2_end_row(step),r2_end_col(step)); features(totalfeatures) = rectA_ii - rectB_ii; totalfeatures = totalfeatures + 1; end step = step+1; r1_start_col(step) = r1_start_col(step-1) + 1; r2_start_col(step) = r2_start_col(step-1) + 1; r1_end_col(step) = r1_end_col(step-1) + 1; r2_end_col(step) = r2_end_col(step-1) + 1; r1_start_row(step) = r1_start_row(step-1); r2_start_row(step) = r2_start_row(step-1); r1_end_row(step) = r1_end_row(step-1); r2_end_row(step) = r2_end_row(step-1); r1_start_col(step):r1_end_col(step); end %j if j < rows step = step + 1; r1_start_row(step) = r1_start_row(step-1) + 1; r2_start_row(step) = r2_start_row(step-1) + 1; r1_end_row(step) = r1_end_row(step-1) + 1; r2_end_row(step) = r2_end_row(step-1) + 1; r1_start_col(step) = r1_start_col(1); r2_start_col(step) = r2_start_col(1); r1_end_col(step) = r1_end_col(1); r2_end_col(step) = r2_end_col(1); end end end end end