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

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.

 채택된 답변

KSSV
KSSV 2017년 7월 3일
Use this:
writetable(struct2table(I3), 'glcmfeatures.xlsx')

댓글 수: 9

It is giving error as below:
??? Undefined function or method 'struct2table' for input arguments of type 'struct'.
what to do...
the value of I3 is: I3 =
Contrast: 0.3396
Correlation: 0.9659
Energy: 0.2668
Homogeneity: 0.9449
KSSV
KSSV 2017년 7월 3일
편집: Image Analyst 2017년 7월 3일
writetable and struct2table were introduced in 2013b. What version you are in?
Try this:
P = [fieldnames(I3),struct2cell(I3)] ;
xlswrite('myfile.xlsx',P) ;
According to what's in "file1", it's the R2007b version. But your code should work with that antique version once the folder is changed. Windows will prevent the file from being written to any folder under Program Files, such as 'C:\Program Files\hemaMATLAB\R2007b\work';
I am using R2007b (antique)version only(bcoz i tried to buy new version they sent msg that they will call within 24 hours but no call i got and I downloaded the trial version but it is not installing.. its giving error..so unable to get new version i tried a lot..... so I had no option using antique one :( hmm..)
And its working... I am very much grateful to you.. THANK YOU SO MUCH.. and I need to copy some 20 image details into an Excel sheet ... how to do it..
And here GLCM is having 4rows of details ... I did writing one line of data into XLSSHEET using for loop... but here for every image i need to store 4lines of details into an excel sheet and after 4lines at 5th line another 4lines of details should be stored like this it should go on copying 4lines details for every image(there are 20 images)please help ...
YOu may proceed like this:
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) ;
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.
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) ;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

hp
2017년 7월 3일

댓글:

hp
2017년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by