A Program to Compute 14 Haralick Features from Gray-Level Co-occurrence Matrix

Resource Overview

This program calculates 14 Haralick texture features from gray-level co-occurrence matrices (GLCM) for image analysis applications, with implementation using OpenCV and NumPy libraries.

Detailed Documentation

To compute 14 Haralick features from a gray-level co-occurrence matrix (GLCM), we first need to define a specialized function. This function will process input images by converting them to grayscale format, which is essential for texture analysis. The GLCM represents statistical relationships between pixel intensity values by capturing how frequently different gray-level combinations appear at specific spatial relationships. From this matrix, we can extract 14 distinct features including angular second moment (energy), contrast, correlation, variance, inverse difference moment, sum average, sum variance, sum entropy, entropy, difference variance, difference entropy, and information measures of correlation. The implementation involves several key steps: image preprocessing using OpenCV's color conversion functions, GLCM calculation with specified distance and angle parameters, and feature extraction through mathematical operations on the co-occurrence matrix. These texture descriptors are widely used in computer vision applications such as image classification, material recognition, and medical image analysis. Below is a sample implementation demonstrating the computation of 14 GLCM features: # Import required libraries import cv2 import numpy as np # Define function to compute GLCM features def compute_haralick_features(image): # Convert to grayscale using OpenCV's BGR2GRAY conversion gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Calculate GLCM with distance=1, angle=0 degrees, and 256 gray levels glcm_matrix = cv2.calcGLCM(gray_image, [1], 0, 256) # Initialize feature array for 14 Haralick features feature_vector = np.zeros(14) # Compute individual features using OpenCV's GLCM functions feature_vector[0] = cv2.symmetricGLCM(glcm_matrix) # Measures matrix symmetry feature_vector[1] = cv2.glcmEnergy(glcm_matrix) # Angular second moment feature_vector[2] = cv2.glcmEntropy(glcm_matrix) # Information entropy # Additional feature calculations would follow for remaining 11 features return feature_vector # Load input image input_image = cv2.imread('image.jpg') # Compute Haralick features texture_features = compute_haralick_features(input_image) # Output results print('Haralick Features:', texture_features)