matlab code to store GLCM features into an Excel sheet..

2 views (last 30 days)
here i have a code after reading an image ... it is resized and GLCM is calculated .. this GLCM features are calculated for folder of images... and I need this to be stored in an excel ... the code i used is:
RGB=imresize(image,[256 256]);
I=rgb2gray(RGB);
I2=graycomatrix(I);
I3=graycoprops(I2);
usecel{1}=I3;
file1 = 'C:\Program Files\hemaMATLAB\R2007b\work\glcmfeatures.xlsx';
xlswrite(file1,usecel{1});
but the below code is giving an error like: ??? Error using ==> xlswrite at 114 Input data must be a numeric, cell, or logical array.
please tell me how to write a matlab code to store GLCM features to store in an Excel sheet.... I need this for comparison.

Accepted Answer

KSSV
KSSV on 3 Jul 2017
Use this:
writetable(struct2table(I3), 'glcmfeatures.xlsx')
  9 Comments
hp
hp on 5 Jul 2017
I tried the code below: dir_in = 'C:\Program Files\hemaMATLAB\R2007b\work\capinput\';
dir_out = 'C:\Program Files\hemaMATLAB\R2007b\work\output\';
file_ext = 'jpg';
listing = dir(strcat(dir_in,'i*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
gdata = cell(num_pages,1);
for imgNum = 1 : num_pages
fprintf('Computing Texture..... %d...\n', imgNum);
image = rgb2gray(imread(strcat(dir_in,file_names{imgNum})));
RGB=imresize(I,[256 256]);
I=rgb2gray(RGB);
I2=graycomatrix(I);
I3=graycoprops(I2);
P = [fieldnames(I3),struct2cell(I3)] ;
P = [fieldnames(I3) struct2cell(I3)] ;
% append more values in loop
Pcell = cell(6,4) ;
Pcell(1:2,:) = P' ;
for i = 3:6
Pcell(i,:) = num2cell(rand(1,4)) ;
end
xlswrite('myfile.xlsx',Pcell) ;
end
and the above code is giving error as follows:
Processing an Image: 1
??? Error using ==> rgb2gray>parse_inputs at 82
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Error in ==> texturetest1 at 21
I=rgb2gray(map);
??? 4lines_of_feature_into_xlsheet |
Error: Unexpected MATLAB expression.
hp
hp on 5 Jul 2017
sorry the above code is not corrected ... here is the code below ... which is giving error:
dir_in = 'C:\Program Files\hemaMATLAB\R2007b\work\capinput\';
dir_out = 'C:\Program Files\hemaMATLAB\R2007b\work\output\';
file_ext = 'jpg';
listing = dir(strcat(dir_in,'i*.',file_ext));
file_names = {listing.name};
num_pages = length(file_names);
for imgNum = 1 : num_pages
fprintf('Computing Texture..... %d...\n', imgNum);
image = rgb2gray(imread(strcat(dir_in,file_names{imgNum})));
I=imresize(image,[256 256]);
I2=graycomatrix(I);
I3=graycoprops(I2);
P = [fieldnames(I3),struct2cell(I3)] ;
P = [fieldnames(I3) struct2cell(I3)] ;
% append more values in loop
Pcell = cell(6,4) ;
Pcell(1:2,:) = P' ;
for i = 3:6
Pcell(i,:) = num2cell(rand(1,4)) ;
end
xlswrite('myfile.xlsx',Pcell) ;
end
and the error is:
Computing Texture..... 1...
??? Index exceeds matrix dimensions.
Error in ==> fourfeatureExcelsheet at 21
Pcell = cell(6,4) ;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!