iKK
iKK

Reputation: 7012

GLCM in opencv2 (Gray-Level Co-occurrence Matrices)

The legacy function GLCM does not perform yet in opencv2. I use the following code:

#import <opencv2/legacy.hpp>

cv::Mat inputIm = [in_image CVMat];
cv::Mat grayIm = [in_image CVGrayscaleMat];

// cv::cvtColor(inputIm, grayIm, cv::COLOR_RGB2GRAY);

// here I get an error: "no matching function..." !!!
CvGLCM* glcm = cvCreateGLCM(grayIm, 1, NULL, 4, CV_GLCM_OPTIMIZATION_LUT);

cvCreateGLCMDescriptors(glcm, CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST);
double d = cvGetGLCMDescriptor(glcm, 0, CV_GLCMDESC_HOMOGENITY );
double a = 1; double *ave = &a;
double s = 1; double *sd = &s;
cvGetGLCMDescriptorStatistics(glcm, CV_GLCMDESC_ENERGY, ave, sd);

NSLog(@"ave = %f sd = %f", *ave, *sd);

I tried already to use the namespace cv::CvGLCM* glcm = cv::cvCreateGLCM(grayIm,.... -- but no change :/

Any help on this is very much appreciated !

Upvotes: 1

Views: 7445

Answers (3)

jjgarsal
jjgarsal

Reputation: 11

I found this when I was looking for GLCM "Implementation of GLCM Haralick Features in openCV", this gets 12 of 14 texture features

https://github.com/Abello966/opencv-haralickfeatures

Upvotes: 1

iKK
iKK

Reputation: 7012

What helped finally was the answer from Alexander Shishkov posted here: link1

I did exchange the texture.cpp code and compiled my opencv-framework again (explained here: link2: i.e. in particular I re-did the last step of the three...).

Doing all that, my glcm-code performs without exception and delivers two numbers per glcm-method.

Upvotes: 3

Roger Rowland
Roger Rowland

Reputation: 26259

The legacy function cvCreateGLCM takes the older IplImage* as its input, so you need to convert your cv::Mat image first.

Try this:

// your input image
cv::Mat grayIm = [in_image CVGrayscaleMat];

// create a legacy image
IplImage pGray = grayIm;

// call function
CvGLCM* glcm = cvCreateGLCM(&pGray, 1, NULL, 4, CV_GLCM_OPTIMIZATION_LUT);

Upvotes: 1

Related Questions