How can I save data from features files into matrix?

i want to save data from 500 images features files every file contain 6 types of features types such as jcd,tamura,..... .,
the problem is that the data for these 6 features are seperated by comma,i want to make six matrices for these 500 image for type of features ,i atteched this file to help
can any one help

댓글 수: 2

"the problem is that the data for these 6 features are seperated by comma" Why is that a problem?
i mean that i want code that save the data for each feature for 500 images .so finally i get 6 matrices the size for each one 500*feature size data .like tamura the size will be 500*18.that i mean.the code will help me to save time to import data for 6 features for 500 images features.with thanks

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

 채택된 답변

per isakson
per isakson 2019년 10월 15일
편집: per isakson 2019년 10월 15일
I understand that "data for each feature for 500 images" is in ONE text file with 500 blocks of six rows. The format is illustrated by im1.txt which contains two blocks.
Try this
>> S = cssm('im1.txt')
S =
1×2 struct array with fields:
JCD
Tamura
ColorLayout
EdgeHistogram
AutoColorCorrelogram
PHOG
>> JCD_matrix = cat( 1, S(:).JCD );
>> whos JCD_matrix
Name Size Bytes Class Attributes
JCD_matrix 2x168 2688 double
where (in one m-file)
function im = cssm( ffs )
%%
fid = fopen( ffs, 'rt' );
buf = textscan( fid, '%s', 'Delimiter', '\n' );
fclose( fid );
buf = buf{1};
%%
len = floor( size(buf,1)/6 ); % number of blocks
im(1,len) = struct( 'JCD',[], 'Tamura',[], 'ColorLayout',[] ...
, 'EdgeHistogram',[], 'AutoColorCorrelogram',[], 'PHOG',[] );
%%
for jj = 1 : len
im(jj).JCD = read( buf{(jj-1)*6 + 1 }, 'JCD' , (jj-1)*6+1 );
im(jj).Tamura = read( buf{(jj-1)*6 + 2 }, 'Tamura' , (jj-1)*6+2 );
im(jj).ColorLayout = read( buf{(jj-1)*6 + 3 }, 'ColorLayout' , (jj-1)*6+3 );
im(jj).EdgeHistogram = read( buf{(jj-1)*6 + 4 }, 'EdgeHistogram' , (jj-1)*6+4 );
im(jj).AutoColorCorrelogram = read( buf{(jj-1)*6 + 5 }, 'AutoColorCorrelogram', (jj-1)*6+5 );
im(jj).PHOG = read( buf{(jj-1)*6 + 6 }, 'PHOG' , (jj-1)*6+6 );
end
end
function row = read( chr, name, n )
cac = strsplit( chr, ':' );
assert( strcmp(cac{1},name),'Row, %d, is "%s". Expected is "%s"', n, cac{1}, name )
num = textscan( cac{2}, '%f', 'Delimiter',',' );
row = reshape( num{1}, 1,[] );
end
If execution time is a problem replace
cac = strsplit( chr, ':' );
by
cac = regexp( chr, ':', 'split' );

댓글 수: 5

i use matlab 2017
.when i tried first code.i got this message
Error: File: Untitled3.m Line: 1 Column: 1
Unexpected MATLAB operator.
also in matlab 2017 relizes this message
Undefined function or variable 'cssm'.
per isakson
per isakson 2019년 10월 15일
편집: per isakson 2019년 10월 15일
I cannot see that "Error: File: Untitled3.m Line: 1 Column: 1" could be caused by my code.
"Undefined function or variable 'cssm'" is because you have not copied and pasted the function I provide in my answer to an m-file, i.e the text that follows after "where (in one m-file)". See function Declare function name, inputs, and outputs
bahaa rabi
bahaa rabi 2019년 10월 16일
편집: per isakson 2019년 10월 16일
very thanks i tried again this 2 codes and got results for only one im . what i do call the all 6 features for 500 im. my images strates from im1 to im5 , and i want 6 feature matrix like for matrix for jcd contains the jcd features for 500 images. thank you for your cooperation.
I wrote: "I understand that "data for each feature for 500 images" is in ONE text file with 500 blocks of six rows. The format is illustrated by im1.txt which contains two blocks."
Why don't you say that I missinterpreted the question?

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

추가 답변 (0개)

카테고리

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

질문:

2019년 10월 14일

댓글:

2019년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by