how do i save extracted feature vectors of an image database?

Hello everybody
i have a DB of images for a CBIR project and i have to extract different types of features (color : using HSV, texture : using LBP) which i already did, now my qs is how to save those extracted features in a dataset of features to which the CBIR system would go back to, to retreive the similar images ? .. is it a ".mat" file or some other way ? and is it possible to gather the different types of features in the same dataset knoing that their vector sizes are different too? can anyone please help

 Réponse acceptée

Yes, you can save your variables in a .mat file. Use the save() function, like
save('answers.mat', 'var1', 'feature2', 'something3');
or whatever. They don't all need to be the same size or even class.

10 commentaires

Thank you Image Analyst, so if i understand well, by saving all the features (of my DB images) in one mat file i can go back to them while retrieving the similar images only by loading the file and specifying the feature needed using a line like this for example :
DB_features = load(fullFileName);
HSV = DB_features.HSV;
i have a kind of ambiguity here can you please help me with it, while retrieving and applying a metric measure, what would be the result or the output ? i mean the metric would calculate the distance between the features of the dataset features and the query image features, how can it show images corresponding to features with the smallest distance ?
Yes, exactly. You tell save what variables you want to save. Then you use load() to recall them. All the variables you saved will be in a structure. If you want them in their own variable with names like they used to have then you can take the field and put it into a variable like you did.
If you compute the difference between an unknown image, and the features you saved for your training set, then you can do that. I don't know what metrics you want to measure. Of course they may have different units or even be unitless. For example you might store the gray level intensity, the mean and stddev of all the individual color channels, the area fraction of something, etc. So you can't just take the Euclidean distance of all of them because the area fraction will be between 0 and 1 and be unitless while the intensities have much larger ranges and have units of gray levels. So you have to figure out some weighting to apply to the various metrics to get some sort of overall similarity index.
Once you have that, you can pull out image names from your database that have similar metrics as your test image. For example like in this extremely cool, interactive CBIR website that recalls images based on colors you tell it.
I appreciate your reponse, and the CBIR website is really cool.
so to answer you, what i want to measure is the HSV and LBP feautures extracted from both the unknown/query image and the database image, i'll use for that the euclidian distance (it could be any other methode euclidian, manhatan distance or mahalanobis ..), i know i can't apply the euclidean distance (for example) on all the metrics just like that, because each would have a distinct specificity to consider (as you gave in the example of intensities and area fraction), and i kind of have the same thing in my case cuz the output feature vector for HSV and LBP are different in size (the HSV gives me a vector of 1x32, and LBP a vector of 1x3776
excuse my question, but the part of pulling out the image names that have similar metrics how does it happen knowing that the distance computing happens only between the query image feature and features of the database images (which are now no longer images with names) ? should we save the features (somehow i don't really know) with the names of images, or do those features stay related to the images and names even if they're now just features (values) stored in their own file (in this case a .mat file) ?
Well you have to store the filename along with its features. I'd recommend a structure array so the image and its features are all kept together. Like
features(k).fileName = filename;
features(k).meanH = meanH;
features(k).meanS = meanS;
features(k).meanV = meanV;
features(k).lbpVector = lbpVector;
etc. for all the features you measure. k is the index and will range from 1 to however many images you have. Then save the structure array in a .mat file:
save('My Features.mat', 'features');
Okey now i got it.
Again Thank you so much for explaning and the time you put into it, and happy new year btw.
i have one more question please, when i created the struct array as you recomanded the fileName field had the same fileName (the last image name) in all the rows, and it's size is 1x16 , it shoulb 200x16 or so. the other fields are good, they all contain features extracted from each of the images.
ps : the fileName is called baseFileName in my code.
how do i fixe that, any advice or suggestion please ?
You need to do
features(k).fileName = filename;
in your loop as I suggested. You're not putting in the index so you're doing
features.fileName = filename;
I did here's the code of it :
for k = numberOfFiles %(which are the 200 images)
features(k).baseFileName = baseFileName;
features(k).HSV_images = HSV_images;
features(k).LBP_images = LBP_images;
save('MyFeatures.mat', 'features');
end
is it possible that it has something to do with the fact that the names has both numbers and letters, ex : 'P0890_output.png' ?
Show the whole loop. You left out the parts where you get new baseFileName, HSV_Images, and LBP_Images. If baseFileName changes in the loop (as it should, along with the images), then the structure array should have different file names.
Got it fixed, it's actually silly as an issue, it was just the ':' missing in the :
k = 1:numberOfFiles
Thank you anyway

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by