SkillAgentSearch skills...

Pyfeats

[GitHub 2021] Open source software for image feature extraction.

Install / Use

/learn @giakoumoglou/Pyfeats

README

<p align="center"> <img src="https://github.com/giakou4/features/blob/main/demo/data/PyFeats Logo v2.png"> </p>

PyFeats

Open-source software for image feature extraction

DOI made-with-python License: MIT version Downloads stars issues-open issues-closed size

Updates

  • 13/06/2023 - Stargazers added on README.md (using star-history)
  • 10/06/2023 - New logo
  • 29/05/2023 - Post on medium

1. Install through pip

Now the project can be found at https://pypi.org/project/pyfeats/. Install using the following command:

pip install pyfeats

Use calling:

import pyfeats

2. Features

The first step for every machine learning algorithm in a computer vision problem is to extract features from the given images. Feature extraction is a critical step in any pattern classification system. In order for the pattern recognition process to be tractable, it is necessary to convert patterns into features, which are condensed representations of the patterns, containing only salient information. Features contain the characteristics of a pattern in a comparable form making the pattern classification possible. Feature extraction can be accomplished manually or automatically.

Manual feature extraction requires identifying and describing the features that are relevant for a given problem and implementing a way to extract those features. In many situations, having a good understanding of the background or domain can help make informed decisions as to which features could be useful. Over decades of research, engineers and scientists have developed feature extraction methods for images. The features inlcuded in here are: Textural Features, Morphological Features, Histogram-based Features, Multi-scale Features, and Moments.

2.1 Textural Features

  1. First Order Statistics/Statistical Features (FOS/SF)
  2. Gray Level Co-occurence Matrix (GLCM/SGLDM)
  3. Gray Level Difference Statistics (GLDS)
  4. Neighborhood Gray Tone Difference Matrix (NGTDM)
  5. Statistical Feature Matrix (SFM)
  6. Law's Texture Energy Measures (LTE/TEM)
  7. Fractal Dimension Texture Analysis (FDTA)
  8. Gray Level Run Length Matrix (GLRLM)
  9. Fourier Power Spectrum (FPS)
  10. Shape Parameters
  11. Gray Level Size Zone Matrix (GLSZM)
  12. Higher Order Spectra (HOS)
  13. Local Binary Pattern (LPB)

2.2 Morphological Features

  1. Grayscale Morphological Analysis
  2. Multilevel Binary Morphological Analysis

2.3 Histogram Based Features

  1. Histogram
  2. Multi-region histogram
  3. Correlogram

2.4 Multi-scale Features

  1. Fractal Dimension Texture Analysis (FDTA)
  2. Amplitude Modulation – Frequency Modulation (AM-FM)
  3. Discrete Wavelet Transform (DWT)
  4. Stationary Wavelet Transform (SWT)
  5. Wavelet Packets (WP)
  6. Gabor Transform (GT)

2.5 Other Features

  1. Zernikes’ Moments
  2. Hu’s Moments
  3. Threshold Adjacency Matrix (TAS)
  4. Histogram of Oriented Gradients (HOG)

3. How to use each feature set

For the following sections, assume

  • f is a grayscale image as a numpy ndarray,
  • mask is an image as a numpy ndarray but with 2 values: 0 (zero) and 1 (one) with 1 indicating the region-of-interest (ROI), where the features shall be calculated (values outside ROI are ignored),
  • perimeter is like mask but indicates the perimeter of the ROI. The demo has an analytic way on how to create mask and perimeter, given a set of coordinates.
<p align="center"> <img width="375" height="130" src="https://github.com/giakou4/features/blob/main/demo/data/f.png"> </p> <p align="center"> <img width="375" height="130" src="https://github.com/giakou4/features/blob/main/demo/data/mask.png"> </p> <p align="center"> <img width="375" height="130" src="https://github.com/giakou4/features/blob/main/demo/data/perimeter.png"> </p>

Note than an analytical description of how each feature is calculated lies in pyfeats.pdf.

3.1 Textural Features

3.1.1 First Order Statistics/Statistical Features (FOS/SF)

First Order Statistics (FOS) are calculated from the histogram of the image which is the empirical probability density function for single pixels. The FOS features are the following: 1) mean, 2) standard deviation, 3) median, 4) mode, 5) skewnewss, 6) kurtosis, 7) energy, 8) entropy, 9) minimal gray level, 10) maximal gray leve, 11) coefficient of variation, 12,13,14,15) percentiles (10, 25, 50, 75, 90) and 16) histogram width.

features, labels = pyfeats.fos(f, mask)

3.1.2 Gray Level Co-occurence Matrix (GLCM/SGLDM)

The Gray Level Co-occurrence Matrix (GLCM) as proposed by Haralick are based on the estimation of the second-order joint conditional probability density functions. The GLGLCM features are the following: 1) angular second moment, 2) contrast, 3) correlation, 4) sum of squares: variance, 5) inverse difference moment, 6) sum average, 7) sum variance, 8) sum entropy, 9) entropy, 10) difference variance, 11) difference entropy, 12,13) information measures of correlation. For each feature, the mean values and the range of values are computed, and are used as two different features sets.

features_mean, features_range, labels_mean, labels_range = pyfeats.glcm_features(f, ignore_zeros=True)

3.1.3 Gray Level Difference Statistics (GLDS)

The Gray Level Difference Statistics (GLDS) algorithm uses first order statistics of local property values based on absolute differences between pairs of gray levels or of average gray levels in order to extract texture measures. The GLDS features are the following: 1) homogeneity, 2) contrast, 3) energy, 4) entropy, 5) mean.

features, labels = pyfeats.glds_features(f, mask, Dx=[0,1,1,1], Dy=[1,1,0,-1])

3.1.4 Neighborhood Gray Tone Difference Matrix (NGTDM)

Neighbourhood Gray Tone Difference Matrix (NDTDM) corresponds to visual properties of texture. The NGTDM features are the following: 1) coarseness, 2) contrast, 3) busyness, 4) complexity, 5) strength.

features, labels = pyfeats.ngtdm_features(f, mask, d=1)

3.1.5 Statistical Feature Matrix (SFM)

The Statistical Feature Matrix measures the statistical properties of pixel pairs at several distances within an image which are used for statistical analysis. The SFM features are the following: 1) coarseness, 2) contrast, 3) periodicity, 4) roughness.

features, labels = pyfeats.sfm_features(f, mask, Lr=4, Lc=4)

3.1.6 Law's Texture Energy Measures (LTE/TEM)

Law’s texture Energy Measures, are derived from three simple vectors of length 3. If these vectors are convolved with themselves, new vectors of length 5 are obtained. By further self-convolution, new vectors of length 7 are obtained. If the column vectors of length l are multiplied by row vectors of the same length, Laws l×l masks are obtained. In order to extract texture features from an image, these masks are convoluted with the image, and the statistics (e.g., energy) of the resulting image are used to describe texture: 1) texture energy from LL kernel, 2) texture energy from EE kernel, 3) texture energy from SS kernel, 4) average texture energy from LE and EL kernels, 5) average texture energy from ES and SE kernels, 6) average texture energy from LS and SL kernels.

features, labels = pyfeats.lte_measures(f, mask, l=7)

3.1.7 Fractal Dimension Texture Analysis (FDTA)

Fractal Dimension Texture Analysis (FDTA) is based on the Fractional Brownian Motion (FBM) Model. The FBM model is used to describe the roughness of nature surfaces. It regards naturally occurring surfaces as the end result of random walks. Such random walks are basic physical processes in our universe. One of the most important parameters to represent a fractal surface is the fractal dimension. A simpler method is to estimate the H parameter (Hurst coefficient). If the image is seen under different resolutions, then the multiresolution fractal (MF) feature vector is obtained.

h, labels = pyfeats.fdta(f, mask, s=3)

3.1.8 Gray Level Run Length Matrix (GLRLM)

A gray level run is a set of consecutive, collinear picture points having the same gray level value. The length of the run is the number of picture points in the run. The GLRLM features are the following: 1) short run emphasis, 2) long run emphasis, 3) gray level non-uniformity, 4) run length non-uniformity, 5) run percentage, 6) low gray level run emphasis, 7) high gray level run emphasis, 8) short low gray level emphasis, 9) short run high gray level emphasis, 10) long run low gray level emphasis, 11) long run high level emphasis.

features, labels = pyfeats.glrlm_features(f, mask, Ng=256)
`

Related Skills

View on GitHub
GitHub Stars243
CategoryDevelopment
Updated1mo ago
Forks30

Languages

Python

Security Score

100/100

Audited on Mar 4, 2026

No findings