function fea=humanFeaExtract(im, opt, showPlot) % feaExtract: Feature extraction for human images % % Usage: % fea=humanFeaExtract(imFile, opt, showPlot) % % Example: % imFile='TrainingDatas216.png'; % im=imread(imFile); % opt=humanFeaExtract('defaultOpt'); % fea=humanFeaExtract(im, opt, 1); % Category: Human image feature extraction % Roger Jang, 20150110 if nargin<1, selfdemo; return; end if ischar(im) && strcmpi(im, 'inputName') % Return the input names fea={'fd1', 'fd2', 'fd3', 'fd4', 'fd5', 'fd6', 'fd7', 'fd8'}; return end if ischar(im) && strcmpi(im, 'defaultOpt') % Set the default options fea.dim=8; % Dummy field to be added later return end if nargin<2||isempty(opt), opt=feval(mfilename, 'defaultOpt'); end if nargin<3, showPlot=0; end % To get binary image im=im2double(im); imBw = im2bw(im, graythresh(im)); % To find boundary of main's object which has the largest length boundarySet = bwboundaries(imBw, 'noholes'); leng = zeros(length(boundarySet),1); for i=1:length(boundarySet) leng(i)=length(boundarySet{i}); end [junk, maxId] = max(leng); boundaryPos=boundarySet{maxId}; % FFT transform X_points = boundaryPos(:,2); Y_points = boundaryPos(:,1); x_fft = fft(X_points); y_fft = fft(Y_points); % computing magnitude value magnitude_X = abs(x_fft); magnitude_Y = abs(y_fft); % computing magnitude of Fourier Descriptors R = sqrt(magnitude_X.^2 + magnitude_Y.^2); first_conponent = R(1); other_conponents = R(2:length(R)); % Get fourier Descriptors vector FourierDescriptors_Vector = other_conponents/first_conponent; % Get 15 coefficiences of Fourier Descriptors temp = FourierDescriptors_Vector(1:opt.dim); fea=temp(:); if showPlot subplot(221);imshow(im); title('Original image'); subplot(222); imshow(imBw); title('BW image and boundary'); for i=1:size(boundaryPos, 1) line(boundaryPos(i,2), boundaryPos(i, 1), 'color', 'r', 'marker', '.'); end subplot(223); plot([magnitude_X(:), magnitude_Y(:)], '.-'); title('Magnitude of FFT of x and y'); subplot(224); plot(fea, '.-'); title('Feature vector'); end % ====== Self demo function selfdemo mObj=mFileParse(which(mfilename)); strEval(mObj.example);