FilterCoOccurrenceMatrix

Parameters
to be certain to have a up to date information you can list all parameters with their description directly with the Filters API (see TutorialC1 in langage C or Tutorial3 in Delphi)

[inImage]
input image type : image

[outImageMonitoring]
you can provide a outImageMonitoring to show the pixel corresponding to the ROI you have setted on the outImage -> try FiltersTest for more information, and have a look on is code type : image

[horizontalDistance]
relative to the current pixel, the x delta for the pixel to calcul the co-occurence type : integer

[verticalDistance]
relative to the current pixel, the y delta for the pixel to calcul the co-occurence type : integer

[xAnalyse]
determine the calcul of the co-occurence 0 -> Intensity 1 -> Red 2 -> Green 3 -> Blue 4 -> Hue 5 -> Saturation type : integer

[scale]
type : integer

[outImage]
the co-occurence matrix : each pixel is in fact a Single (4 octets) type : image

[features_*]
features_angularSecondMoment features_energy features_entropy features_contrast features_dissimilarity features_inverseDifferenceMoment features_mean_i/j features_variance_i/j features_correlation type : float

C
void testCoOccurrenceMatrix {	PFBitmap32 fImageTest = image_createImageTest( 512, 512 ); //PFBitmap32 outImageMonitoring = image_createImageLike( fImageTest ); __int32 filterCoOccurrenceMatrix = filters_createFilter( "filterCoOccurrenceMatrix" ); filters_setParameterImage( filterCoOccurrenceMatrix, "inImage", fImageTest ); //filters_setParameterImage( filterCoOccurrenceMatrix, "outImageMonitoring", outImageMonitoring ); filters_setParameterInteger( filterCoOccurrenceMatrix, "horizontalDistance", 1 ); filters_setParameterInteger( filterCoOccurrenceMatrix, "verticalDistance", 0 ); filters_setParameterInteger( filterCoOccurrenceMatrix, "xAnalyse", 0 ); // Intensity filters_setParameterInteger( filterCoOccurrenceMatrix, "yAnalyse", 0 ); // Intensity filters_setParameterFloat( filterCoOccurrenceMatrix, "scale", 1 );

filters_run( filterCoOccurrenceMatrix ); // get outImage PFBitmap32 outImage = filters_getOutputImage( filterCoOccurrenceMatrix, "outImage" ); helper_saveImage( outImage, "C:/DEV/FiltersTutorial/Bin/tutorialC3_CoOccurrenceMatrix_outImage.bmp" ); // and features float tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_angularSecondMoment" ); printf( "features_angularSecondMoment = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_energy" ); printf( "features_angularSecondMoment = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_entropy" ); printf( "features_entropy = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_contrast" ); printf( "features_contrast = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_dissimilarity" ); printf( "features_dissimilarity = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_inverseDifferenceMoment" ); printf( "features_inverseDifferenceMoment = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_mean_i" ); printf( "features_mean_i = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_mean_j" ); printf( "features_mean_j = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_variance_i" ); printf( "features_variance_i = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_variance_j" ); printf( "features_variance_j = %f \n", tmpSingle ); tmpSingle = filters_getOutputFloat( filterCoOccurrenceMatrix, "features_correlation" ); printf( "features_correlation = %f \n", tmpSingle ); filters_deleteFilter( filterCoOccurrenceMatrix ); image_freeImage( fImageTest ); }

Delphi
procedure TFormMain.btnTextureComputeClick(Sender: TObject); var filterCoOccurrenceMatrix : Integer; imageCoOccurrenceMatrix, imageMask : PFBitmap32; tmpSingle : Single; i, iMax, j, jMax : Integer; value : Single; features_occurrenceMax : Single; features_occurrenceMax_col, features_occurrenceMax_row : Integer; begin txtOutput.Clear; // load image to analyse in 'imageLoaded' cmdLoadClick( Self );

// create filter 'filterCoOccurrenceMatrix' filterCoOccurrenceMatrix := createFilter( 'filterCoOccurrenceMatrix' ); // set 'inImage' setParameterImage( filterCoOccurrenceMatrix, 'inImage', imageLoaded ); // we would like to analyse only a part of the image, we use a mask // load the mask image imageMask := loadOneImage( '.\texture_mask.jpg' ); // set 'mask' setParameterImage( filterCoOccurrenceMatrix, 'mask', imageMask ); // set pixels to compare : p1(c,r) <-> p2(c+1,r+0) setParameterInteger( filterCoOccurrenceMatrix, 'horizontalDistance', 1 ); setParameterInteger( filterCoOccurrenceMatrix, 'verticalDistance', 0 ); // set data to compare : p1(0=Intensity) <-> p2(0=Intensity) setParameterInteger( filterCoOccurrenceMatrix, 'xAnalyse', 0 ); setParameterInteger( filterCoOccurrenceMatrix, 'yAnalyse', 0 ); // set 'scale' setParameterFloat( filterCoOccurrenceMatrix, 'scale', 1 ); // run run( filterCoOccurrenceMatrix );

// show build in texture features computed by the filter tmpSingle := getOutputFloat( filterCoOccurrenceMatrix, 'features_angularSecondMoment' ); txtOutput.Lines.Add( 'features_angularSecondMoment = ' + FloatToStrF(tmpSingle,ffFixed,10,10) ); tmpSingle := getOutputFloat( filterCoOccurrenceMatrix, 'features_energy' ); txtOutput.Lines.Add( 'features_energy = ' + FloatToStrF(tmpSingle,ffFixed,10,10) ); tmpSingle := getOutputFloat( filterCoOccurrenceMatrix, 'features_entropy' ); txtOutput.Lines.Add( 'features_entropy = ' + FloatToStrF(tmpSingle,ffFixed,10,10) ); tmpSingle := getOutputFloat( filterCoOccurrenceMatrix, 'features_contrast' ); txtOutput.Lines.Add( 'features_contrast = ' + FloatToStrF(tmpSingle,ffFixed,10,10) ); tmpSingle := getOutputFloat( filterCoOccurrenceMatrix, 'features_inverseDifferenceMoment' ); txtOutput.Lines.Add( 'features_inverseDifferenceMoment = ' + FloatToStrF(tmpSingle,ffFixed,10,10) );

// now we will compute our own texture features : the mean // get 'outImage' (= the co-occurrence matrix) (this image contains float value, not pixels) imageCoOccurrenceMatrix := getOutputImage( filterCoOccurrenceMatrix, 'outImage' ); features_occurrenceMax := -1.0; features_occurrenceMax_col := -1; features_occurrenceMax_row := -1; iMax := imageCoOccurrenceMatrix.Height-1; jMax := imageCoOccurrenceMatrix.Width-1; for i:=0 to iMax do begin for j:=0 to jMax do begin value := image.getPixelAsSingle( imageCoOccurrenceMatrix, j, i ); if value>features_occurrenceMax then begin features_occurrenceMax := value; features_occurrenceMax_col := j;       features_occurrenceMax_row := i;      end; end; end; txtOutput.Lines.Add( 'my feature : features_occurrenceMax = ' + FloatToStrF(features_occurrenceMax,ffFixed,5,10) +   ', for co-occurrence of intensity [' + IntToStr(features_occurrenceMax_col) + ']' +    ' and intensity [' + IntToStr(features_occurrenceMax_row) + ']' );

// delete the filter deleteFilter( filterCoOccurrenceMatrix ); // delete 'imageMask' image.freeImage( imageMask ); end;

Links
"The GLCM Tutorial Home Page" by Mryka Hall-Beyer