Creating Feature vector in .mat file

I wanted to create a feature vector for training dataset and wanted to store all feature as rows in the.mat file. The .mat file must be in the form
I am able to extract Feature of 1 image and store it in excel file or .mat file but not able to extract all image feature and store it in .mat file. Can anyone knows this?

4 comentarios

KSSV
KSSV el 18 de Jun. de 2017
Are the dimensions of features of all images same?
dpb
dpb el 18 de Jun. de 2017
Besides KSSV's request for needed info, show us what you've tried...descriptions aren't sufficient to debug.
dpb
dpb el 18 de Jun. de 2017
Don't expect folks to go somewhere else...post the info here or use stackoverflow, your choice.
Neha singh
Neha singh el 19 de Jun. de 2017
Editada: Neha singh el 19 de Jun. de 2017
Hi @KSSV, All the dimension of the images are same. So here is my sample code .
I am able to get
xpecting somthing to do like

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 19 de Jun. de 2017
graycoprops returns a structure containing the requested statistics in fields of each name; hence you got what you requested in the .mat file.
To convert that structure to an array of contiguous features, use
features=struct2array(stats);
if all the features returned are commensurately-sized arrays (and I don't know if that is true or not; I don't have Image Processing TB to test). If not, you'd have to take the variously-shaped/sized arrays in the various structure names and convert them individually to linear vectors to concatenate by row.
In your code above, even when you're concatenating the structs into mydataGLCM, you've got the initialization of creating the empty container variable INSIDE the loop so you end up with only the last one as that throws away all the previous.
PS: Why do you continue to make it so difficult to try to help by pasting essentially nearly illegible images owing to their size plus one can't do anything with the code without typing everything in again. Copy and paste text and code so folks here have a chance (and then be sure to format it so it's legible using the {}Code button where needed.

7 comentarios

Thanks for your suggestion @ dpb at that movement I was just having the snap in my mail. I tried this:
clear;
file_list = dir('C:\Users\Neha\workspace_matlab\My Project\final
project\output\GLCM\*.jpg');
nfiles = length(file_list);
mydataGLCM = [];
for k = 1 : nfiles
I = imread(strcat('C:\Users\Neha\workspace_matlab\My
Project\final project\output\GLCM\',file_list(k).name));
if length(size(I))== 3 %check if the image I is color
I=rgb2gray(I);
end
GLCM_values = graycomatrix(I);
stats = graycoprops(GLCM_values{'contrast','homogeneity','Correlation','Energy'});
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
feat = [Contrast,Correlation,Energy,Homogeneity];
mydataGLCM = [mydataGLCM, feat(:)];
if k == 1
save('newMethod.mat','mydataGLCM');
else
save('newMethod.mat','mydataGLCM','-append');
end
end
But this is storing features in a column-wise. 1 images feature are stored in 1 column. It should be row wise.
I think the question is clear now @ dpb
Thanks
dpb
dpb el 24 de Jun. de 2017
"images feature are stored in 1 column."
Then transpose the column vector to a row vector with .'
Sarajuddeen Nasrat
Sarajuddeen Nasrat el 27 de Oct. de 2017
hi dear when i want run your code i get error from matlab that is as follow: Cell contents reference from a non-cell array object. how can i correct it.
dpb
dpb el 28 de Oct. de 2017
Don't use {} ("the curlies") to subscript what isn't a cell array.
fadi ssuhimat
fadi ssuhimat el 11 de Feb. de 2020
don't use it, where?
munipraveena rela
munipraveena rela el 30 de Mzo. de 2021
mydataGLCM = [mydataGLCM; feat(:)];
stores data in row wise
munipraveena rela
munipraveena rela el 30 de Mzo. de 2021
mydataGLCM = [mydataGLCM; feat]

Iniciar sesión para comentar.

Más respuestas (1)

fadi ssuhimat
fadi ssuhimat el 11 de Feb. de 2020

0 votos

did you get the right answer... I have same problem now?

Etiquetas

Preguntada:

el 18 de Jun. de 2017

Comentada:

el 30 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by