日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

使用HOG+LBP实现动物分类:matlab版本

發(fā)布時(shí)間:2024/4/14 循环神经网络 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用HOG+LBP实现动物分类:matlab版本 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.訓(xùn)練集測(cè)試集劃分(同上一篇)

2.代碼部分

%% 利用HOG + LBP分類%% 1 數(shù)據(jù)集,包括訓(xùn)練的和測(cè)試的 currentPath = pwd; % 獲得當(dāng)前的工作目錄imdsTrain = imageDatastore(fullfile(pwd,'train_images'),... 'IncludeSubfolders',true,... 'LabelSource','foldernames'); % 載入圖片集合imdsTest = imageDatastore(fullfile(pwd,'test_image')); % imdsTrain = imageDatastore('C:\Program Files\MATLAB\R2017a\bin\proj_xiangbin\train_images',... % 'IncludeSubfolders',true,... % 'LabelSource','foldernames'); % imdsTest = imageDatastore('C:\Program Files\MATLAB\R2017a\bin\proj_xiangbin\test_image'); %% 2 對(duì)訓(xùn)練集中的每張圖像進(jìn)行hog特征提取,測(cè)試圖像一樣 % 預(yù)處理圖像,主要是得到features特征大小,此大小與圖像大小和Hog特征參數(shù)相關(guān) %% LBP參數(shù) imageSize = [256,256];% 對(duì)所有圖像進(jìn)行此尺寸的縮放 I = readimage(imdsTrain,1); I = imresize(I,imageSize); I = rgb2gray(I); lbpFeatures = extractLBPFeatures(I,'CellSize',[16 16],'Normalization','None'); numNeighbors = 8; % Upright = false; numBins = numNeighbors*(numNeighbors-1)+3; % numNeighbors+2; lbpCellHists = reshape(lbpFeatures,numBins,[]); lbpCellHists = bsxfun(@rdivide,lbpCellHists,sum(lbpCellHists)); lbpFeatures = reshape(lbpCellHists,1,[]); % 對(duì)所有訓(xùn)練圖像進(jìn)行特征提取 numImages = length(imdsTrain.Files); featuresTrain1 = zeros(numImages,size(lbpFeatures,2),'single'); % featuresTrain為單精度 scaleImage = imresize(image1,imageSize); [features, visualization] = extractHOGFeatures(scaleImage,'CellSize',[8,8]); featuresTrain2 = zeros(numImages,size(features,2),'single'); % featuresTrain為單精度 for i = 1:numImages imageTrain = readimage(imdsTrain,i); imageTrain = imresize(imageTrain,imageSize); % LBPI = rgb2gray(imageTrain);lbpFeatures = extractLBPFeatures(I,'CellSize',[16 16],'Normalization','None');numNeighbors = 8;numBins = numNeighbors*(numNeighbors-1)+3;lbpCellHists = reshape(lbpFeatures,numBins,[]);lbpCellHists = bsxfun(@rdivide,lbpCellHists,sum(lbpCellHists));lbpFeatures = reshape(lbpCellHists,1,[]);featuresTrain1(i,:) = lbpFeatures; % HOGfeaturesTrain2(i,:) = extractHOGFeatures(imageTrain,'CellSize',[8,8]); end % 特征合并 featuresTrain = [featuresTrain1,featuresTrain2];% 所有訓(xùn)練圖像標(biāo)簽 trainLabels = imdsTrain.Labels; % 開始svm多分類訓(xùn)練,注意:fitcsvm用于二分類,fitcecoc用于多分類,1 VS 1方法 classifer = fitcecoc(featuresTrain,trainLabels); correctCount = 0; %% 預(yù)測(cè)并顯示預(yù)測(cè)效果圖 numTest = length(imdsTest.Files); for i = 1:numTest testImage = readimage(imdsTest,i); % imdsTest.readimage(1)scaleTestImage = imresize(testImage,imageSize); % LBPI = rgb2gray(scaleTestImage);lbpFeatures = extractLBPFeatures(I,'CellSize',[16 16],'Normalization','None');numNeighbors = 8;numBins = numNeighbors*(numNeighbors-1)+3;lbpCellHists = reshape(lbpFeatures,numBins,[]);lbpCellHists = bsxfun(@rdivide,lbpCellHists,sum(lbpCellHists));featureTest1 = reshape(lbpCellHists,1,[]);% HOGfeatureTest2 = extractHOGFeatures(scaleTestImage,'CellSize',[8,8]); % 合并featureTest = [featureTest1,featureTest2];[predictIndex,score] = predict(classifer,featureTest); figure;imshow(imresize(testImage,[256 256]));imgName = imdsTest.Files(i);tt = regexp(imgName,'\','split');cellLength = cellfun('length',tt);tt2 = char(tt{1}(1,cellLength));% 統(tǒng)計(jì)正確率if strfind(tt2,char(predictIndex))==1correctCount = correctCount+1;endtitle(['predictImage: ',tt2,'--',char(predictIndex)]); fprintf('%s == %s\n',tt2,char(predictIndex)); end % 顯示正確率 fprintf('分類結(jié)束,正確了為:%.3f%%\n',correctCount * 100.0 / numTest);

  

轉(zhuǎn)載于:https://www.cnblogs.com/xiangbin1207/p/6937017.html

總結(jié)

以上是生活随笔為你收集整理的使用HOG+LBP实现动物分类:matlab版本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。