Question

I am trying to load feature vectors into classifiers such as a k-nearest neighbors classifier.

I have my code for GLCM, so I get contrast, correlation, energy, homogeneity in numbers (feature vectors).

My question is, how can I save every set of feature vectors from all the training images? I have seen somewhere that people had a .set file to load into classifiers (may be it is a special case for the particular classifier toolbox).

load 'mydata.set';

for example.

I suppose it does not have to be a .set file.
I'd just need a way to store all the feature vectors from all the training images in a separate file that can be loaded.

I've google, and I found this that may be useful but I am not entirely sure.

Thanks for your time and help in advance.

Regards.

Was it helpful?

Solution

If you arrange your feature vectors as the columns of an array called X, then just issue the command

save('some_description.mat','X'); 

Alternatively, if you want the save file to be readable, say in ASCII, then just use this instead:

save('some_description.txt', 'X', '-ASCII');

Later, when you want to re-use the data, just say

var = {'X'}; % <-- You can modify this if you want to load multiple variables.

load('some_description.mat', var{:});
load('some_description.txt', var{:}); % <-- Use this if you saved to .txt file.

Then the variable named 'X' will be loaded into the workspace and its columns will be the same feature vectors you computed before.

You will want to replace the some_description part of each file name above and instead use something that allows you to easily identify which data set's feature vectors are saved in the file (if you have multiple data sets). Your array of feature vectors may also be called something besides X, so you can change the name accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top