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

6 views (last 30 days)
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

Accepted Answer

Vineet Joshi
Vineet Joshi on 9 Dec 2021
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by