how to store and extract features for .txt files as like .png and .jpg images?

1 次查看(过去 30 天)
I have taken a kaggle image dataset which contains star, triangle, circle and square. I have considered some images for training and testing and I have classified them using SVM:
clc;
clear all;
close all;
path1='D:\imagedb\trainimg';
path2='D:\imagedb\testimg';
traindb=imageDatastore(path1,'IncludeSubfolders',true,'LabelSource','foldernames');
testdb=imageDatastore(path2,'IncludeSubfolders',true,'LabelSource','foldernames');
%Training
img=readimage(traindb,1);
CS=[16,16];
[hogfv,hogvis]=extractHogfeatures(img,'cellsize',CS);
hogfeaturesize=length(hogfv);
totaltrainimages=numel(traindb.Files);
trainingfeatures=zeros(totaltrainimages,hogfeaturesize,'single');
for i=1:totaltrainimages
img=readimage(traindb,i);
trainingfeatures(i,:)=extractHogfeatures(img,'cellsize',CS);
end
traininglabels=traindb.Labels;
classifier=fitcecoc(trainingfeatures,traininglabels);
%testing all test images
totaltestimages=numel(testdb.Files);
testfeatures=zeros(totaltestimages,hogfeaturesize,'single');
for i=1:totaltestimages
imgt=readimage(testdb,i);
testfeatures(i,:)=extractHogfeatures(imgt,'cellsize',CS);
end
testlabels=testdb.Labels;
predictedlabels=predict(classifier,testfeatures);
accuracy=(sum(predictedlabels==testlabels)/numel(testlabels))*100
plotconfusion(testlabels,predictedlabels)
In the same manner I want to classify objects like metal pipe, steel box and plastic box buried under the ground. The imaging is done by using ground penetrating radar which actually sends EM pulses into the ground and generates B-scan images but the images not exactly give original images, it will give hyperbola shape only. I have generated some database by varying object sizes, depths and dielectric constants. Imaging is done by imagesc not by imshow. I could not save the image as .jpg or .png etc formats. so that I cannot read by imread or readimage. after plotting I have saved the data in excel '.txt' format and I'm recalling by 'dlmread'. like below
y=dlmread('metal_pipe_er2.6.txt', '\t', 0, 0);
figure,imagesc(X,z_depth,y)
now I want to extract HOG features for my text files as like imaging database and classify using SVM. please help me

采纳的回答

Vineet Joshi
Vineet Joshi 2021-12-9
Hi
extractHOGFeatures will give you extracted HOG features as long as the input I is an image.
In order to make it work in your case, you can read the excel file in MATLAB and convert each row into an mXn size image.
You can store the features in a similar way, by saving the 1XN vector as rows.
Hope this helps.
Thanks

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by