当前位置:   article > 正文

Matlab实现图像数据集的特征提取与分类器设计_掌握几种常用的局部特征点图像特征提取算法,构建一个图像分类器,并在matlab环境下

掌握几种常用的局部特征点图像特征提取算法,构建一个图像分类器,并在matlab环境下

包含内容:

  1. 特征:LBP、HOG、Gabor、GLCM(灰度共生矩阵)、Hu(Hu矩);
  2. 分类器:KNN(K-近邻)、SVM(支持向量机)、NB(朴素贝叶斯)、Tree(决策树)。

数据集读入函数代码:

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

特征提取函数代码:

  1. LBP
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  1. HOG
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. Gabor
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 =<
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/354601
推荐阅读
相关标签
  

闽ICP备14008679号