赞
踩
function [trainData,trainLabels,testData,testLabels] = ReadDataSet(fileRoot,imageFormat,trainNum,testNum) %读取数据集 dataSetFiles = dir(strcat(fileRoot,'\s*')); classNum = length(dataSetFiles); trainLabels = []; testLabels = []; for i = 1 : classNum imageData = dir(strcat(fileRoot,'\',dataSetFiles(i).name,'\*.',imageFormat)); for j = trainNum(1) : trainNum(2) image = im2double(imread(strcat(fileRoot,'\',dataSetFiles(i).name,'\',imageData(j).name))); trainData(:,:,(trainNum(2)-trainNum(1)+1)*(i-1)+j-trainNum(1)+1) = image; trainLabels = [trainLabels;i]; end for j = testNum(1) : testNum(2) image = im2double(imread(strcat(fileRoot,'\',dataSetFiles(i).name,'\',imageData(j).name))); testData(:,:,(testNum(2)-testNum(1)+1)*(i-1)+j-testNum(1)+1) = image; testLabels = [testLabels;i]; end end end
function total_LBP_Features = Extract_LBP_Features(data)
%提取LBP特征
[~,~,totalNum] = size(data);
total_LBP_Features = [];
for i = 1 : totalNum
LBP_Features = extractLBPFeatures(data(:,:,i),'CellSize',[16,16],'Upright',true);
numNeighbors = 8;
numBins = numNeighbors*(numNeighbors-1)+3;
LBP_CellHists = reshape(LBP_Features,numBins,[]);
LBP_CellHists = bsxfun(@rdivide,LBP_CellHists,sum(LBP_CellHists));
LBP_Features = reshape(LBP_CellHists,1,[]);
total_LBP_Features = [total_LBP_Features;LBP_Features];
end
end
function total_HOG_Features = Extract_HOG_Features(data)
%提取HOG特征
[~,~,totalNum] = size(data);
total_HOG_Features = [];
for i = 1 : totalNum
total_HOG_Features = [total_HOG_Features;extractHOGFeatures(data(:,:,i))];
end
end
function total_Gabor_Features = Extract_Gabor_Features(data)
%提取Gabor特征
[~,~,totalNum] = size(data);
total_Gabor_Features = [];
GaborArray = gabor(10,[0,45,90,135]);
for i = 1 : totalNum
total_Gabor_Features =<
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。