Saving different 'graycoprops' properties values on a matrix [MATLAB]

3.2k views Asked by At


I've a picture. I create the co-occurrence matrix (graycomatrix) to extract different properties (contrast, correlation) etc on it (graycoprops)

x = []
for a lot of pictures, do the same:
    imgB = imread('currentLoopImage.jpg')

    contrast = graycoprops(graycomatrix(rgb2gray(imgB)), 'Contrast')
    correlation = graycoprops(graycomatrix(rgb2gray(imgB)), 'Correlation')
    energy = graycoprops(graycomatrix(rgb2gray(imgB)), 'Energy')
    homogeneity = graycoprops(graycomatrix(rgb2gray(imgB)), 'Homogeneity')

    x = [x;contrast;correlation;energy;homogeneity]

The thing is that I need to save all the values on that matrix X, but I get the following error:

CAT arguments are not consistent in structure field names.

As this is the output I get from each type:

homogeneity = 

    Homogeneity: 0.8587

There are different types, so I can't save them on the X matrix.
The output matrix X, should save only the numbers, and ignore that "Homogenity"

Can someone tell me who can I do this?

1

There are 1 answers

0
John Colby On BEST ANSWER

From the graycoprops() example:

>> GLCM = [0 1 2 3;1 1 2 3;1 0 2 0;0 0 0 3];
>> stats = graycoprops(GLCM)

stats = 

       Contrast: 2.8947
    Correlation: 0.0783
         Energy: 0.1191
    Homogeneity: 0.5658

Then just do:

>> x = struct2array(stats)

ans =

    2.8947    0.0783    0.1191    0.5658

Also note that you can include all your images in an m x n x p matrix and process them all at once, instead of using the for loop. For example:

>> GLCM(:,:,2) = GLCM;
>> cell2mat(struct2cell(stats))

ans =

    2.8947    2.8947
    0.0783    0.0783
    0.1191    0.1191
    0.5658    0.5658