0

I am doing a feature extraction using glcm method. The glcm output are in 'struct' type, while I need the output in double type.

So, I've tried to convert it using several code showed below.

To get Fetest1 code:

srcFile = dir('D: datatest\*.png');
fetest1 = []; %or fetrain1
for b = 1:length(srcFile)
    file_name = strcat('D:datatest\',srcFile(b).name);
    B = imread(file_name);
%   [fiturtest] = feature_extractor (B);
    [g] = glcm (B);
    [g] = struct2cell (g);
    [fiturtest] = cell2mat (g);  %fiturtrain
%   [c] = CobaDCT (A);
%   [fitur] = cobazigzag(c);
%   arr(:,a) = fitur;
    fetest1 = [fetest1 fiturtest];  %fiturtrain
%   vectorname = strcat(file_name,'_array.mat');

end
 save ('fetest1.mat','fetest1'); %fetrain1

To get Fetrain1 code:

srcFiles = dir('D:datatrain\*.png');
fetrain1 = [];
for a = 1:length(srcFiles)
    file_name = strcat('D:datatrain\',srcFiles(a).name);
    A = imread(file_name);
    [fiturtrain] = feature_extractor (A);
%   [c] = CobaDCT (A);
%   [fitur] = cobazigzag(c);
%     fiturtrain (:,a) = fiturtrain ;
    fetrain1 = [fetrain1 fiturtrain];
%   vectorname = strcat(file_name,'_array.mat');
end
 save ('fetrain1.mat','fetrain1');

The output of the whole process is fetrain1 and fetest1 variables. I run the same code to get fetest1 and fetrain1, but fetest1 is in 'double' type, while fetrain is in 'complex double' type.

enter image description here

and

enter image description here

I need to convert fetrain1 from 'complex double' type into 'double' type, so I can use the variable for the next step. Training step using Neural Network method.

Any suggestion would be very appreciated.

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Ana Ain
  • 173
  • 1
  • 3
  • 14
  • 1
    The absolute value of a complex number is returned by `abs`. The real part and imaginary part are returned by `real` and `imag`, respectively. The _real_ question is: what would you choose, and why? – buzjwa May 19 '16 at 10:44
  • I need your help for Arabic character segmentation, can I have your email? – Hamed May 20 '16 at 14:10
  • with pleasure @Hamed . ana.ainul@gmail.com – Ana Ain May 21 '16 at 00:00

1 Answers1

0

If you are estracting features by the GLCM method you can do:

srcFile = dir('D: datatest\*.png');
fetest1 = []; %or fetrain1

for b = 1:length(srcFile)
    file_name = strcat('D:datatest\',srcFile(b).name);
    B = imread(file_name);

    imG = rgb2gray(B);

    % create gray-level co-occurrence matrix from image
    gimg = graycomatrix(imG);

    % extract properties of gray-level co-occurrence matrix
    stats = graycoprops(gimg, 'all');

    features = [stats.Energy stats.Homogeneity stats.Correlation stats.Contrast];

    fetest1 = cat(1, fetest1, features);
end
SamuelNLP
  • 4,038
  • 9
  • 59
  • 102
  • thanks for the suggestion. But, I've already have GLCM function, the original source code is from here http://www.mathworks.com/matlabcentral/fileexchange/22187-glcm-texture-features What I need now, is to get the appropriate output. fetrain1 in 'double' type. So, I can use it in the next step. – Ana Ain May 19 '16 at 18:28