How to create database to store extracted values?

6 Ansichten (letzte 30 Tage)
Elias Unk
Elias Unk am 19 Jun. 2017
Beantwortet: Jaynik am 8 Nov. 2024 um 5:51
I have extracted 110 features of an image and input them in a features vector A:
A=[f1,f2,f3,f4....,f110];
How can i create a function that'll take a folder path as input and extract the features of every image and place it in a file to create a matrix of feature vectors of each sample , each row represent the parameters of a different sample and each column represent a different feature. Note that'll need to call those vectors back from the database in the main code.

Antworten (1)

Jaynik
Jaynik am 8 Nov. 2024 um 5:51
Hi Elias,
Following is a sample function that you can use for creating a '.mat' file of features. You will need to change it based on your requirements.
function createFeatureDatabase(folderPath, outputFile)
% Get list of all image files in the folder
imageFiles = dir(fullfile(folderPath, '*.jpg')); % Adjust the extension as needed
numImages = length(imageFiles);
% Initialize an empty matrix to store features
featureMatrix = [];
for i = 1:numImages
img = imread(fullfile(folderPath, imageFiles(i).name));
% Extract features (replace this with your actual feature extraction code)
features = extractFeatures(img);
% Append the features to the feature matrix
featureMatrix = [featureMatrix; features];
end
% Save the feature matrix to a file
save(outputFile, 'featureMatrix');
end
createFeatureDatabase('path/to/your/folder', 'featureDatabase.mat');
To load the feature matrix and create the database:
load('featureDatabase.mat', 'featureMatrix');
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by