0% found this document useful (0 votes)
12 views2 pages

GLCM Texture Feature Extraction Guide

The document outlines a process for texture feature extraction using the Gray Level Co-occurrence Matrix (GLCM) from an image. It includes steps for reading and preprocessing the image, quantizing it, computing GLCMs in multiple directions, extracting texture features like contrast and energy, and displaying the results. Additionally, it offers an option to average the features across different angles.

Uploaded by

Meeradevi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

GLCM Texture Feature Extraction Guide

The document outlines a process for texture feature extraction using the Gray Level Co-occurrence Matrix (GLCM) from an image. It includes steps for reading and preprocessing the image, quantizing it, computing GLCMs in multiple directions, extracting texture features like contrast and energy, and displaying the results. Additionally, it offers an option to average the features across different angles.

Uploaded by

Meeradevi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Texture Feature Extraction –GLCM

%% ===============================
% GLCM Texture Feature Extraction
% ===============================
clc; clear; close all;

%% Step 1: Read and preprocess image


I = imread('[Link]'); % Replace with your image
figure; imshow(I); title('Original Image');

% Convert to grayscale if RGB


if size(I,3) == 3
Igray = rgb2gray(I);
else
Igray = I;
end

%% Step 2: Quantize image (optional)


% Reduce gray levels for smaller GLCM
Igray = uint8(floor(double(Igray)/16)); % 16 gray levels

%% Step 3: Compute GLCMs in multiple directions


offsets = [0 1; -1 1; -1 0; -1 -1]; % 0°, 45°, 90°, 135°
glcms = graycomatrix(Igray, 'Offset', offsets);

%% Step 4: Extract texture features for each GLCM


numGLCMs = size(glcms,3);
contrast = zeros(1,numGLCMs);
energy = zeros(1,numGLCMs);
homogeneity = zeros(1,numGLCMs);
correlation = zeros(1,numGLCMs);

for k = 1:numGLCMs
stats = graycoprops(glcms(:,:,k),
{'Contrast','Energy','Homogeneity','Correlation'});
contrast(k) = [Link];
energy(k) = [Link];
homogeneity(k) = [Link];
correlation(k) = [Link];
end

%% Step 5: Display features


angles = [0 45 90 135];
fprintf('GLCM Texture Features:\n');
fprintf('Angle\tContrast\tEnergy\tHomogeneity\tCorrelation\n');
for k = 1:numGLCMs
fprintf('%d\t%.4f\t\t%.4f\t%.4f\t\t%.4f\n', angles(k), contrast(k),
energy(k), homogeneity(k), correlation(k));
end

%% Step 6: Optional - Average features across angles


avgContrast = mean(contrast);
avgEnergy = mean(energy);
avgHomogeneity = mean(homogeneity);
avgCorrelation = mean(correlation);

fprintf('\nAverage Texture Features:\n');


fprintf('Contrast: %.4f\nEnergy: %.4f\nHomogeneity: %.4f\nCorrelation: %.4f\
n', ...
avgContrast, avgEnergy, avgHomogeneity, avgCorrelation);

You might also like