---
title: Histogram of Oriented Gradients (HOG1D)
url: https://www.emergentmind.com/topics/histogram-of-oriented-gradients-hog1d
type: topic
---

# Histogram of Oriented Gradients (HOG1D)

The Histogram of Oriented Gradients for One-Dimensional Signals (HOG-1D) is a feature extraction method designed to characterize local shape patterns in real-valued 1D data. Unlike traditional HOG descriptors applied to multidimensional (e.g., image, video) domains, HOG-1D operates on sequences such as logging traces or time series, providing orientation-sensitive, block-normalized vector representations that facilitate downstream tasks such as sequence alignment. In recent applications, notably within borehole image depth-matching workflows, HOG-1D has been integrated as a primary component of the shape descriptor combined with raw signal values, yielding robust results in scenarios presenting complex textures, depth shifts, and localized scaling perturbations [2512.01611].

## 1. Mathematical Framework of HOG-1D

HOG-1D consists of four sequential operations: gradient computation, orientation mapping, histogram bin quantization, and block-wise normalization.

### 1.1 Gradient Computation
Given a signal $x = (x_1, x_2, \dots, x_n)$:

- For interior samples ($2 \leq i \leq n-1$): $g_i = x_{i+1} - x_{i-1}$
- Edge handling: $g_1 = x_2 - x_1$, $g_n = x_n - x_{n-1}$

This derivative approximation (centered difference) emphasizes local changes and is applied without pre-filtering, exploiting the inherent high-pass characteristics.

### 1.2 Orientation Encoding
The gradient $g_i$ is transformed into a pseudo-angle:
\[
\theta_i = \arctan(g_i),\quad \theta_i \in [-\frac{\pi}{2},\frac{\pi}{2}]
\]
This embedding preserves sign and relative magnitude over a bounded interval.

### 1.3 Orientation Binning and Voting
The angular range $[-\frac{\pi}{2}, \frac{\pi}{2}]$ is partitioned into $K$ bins (with $K=10$):

- Bin centers: $\theta_k = -\frac{\pi}{2} + (k-\frac{1}{2})\Delta\theta$,  $\Delta\theta=\frac{\pi}{K}$
- For each sample $i$, votes $|g_i|$ are distributed to adjacent bins using triangular interpolation:
    - $d_{ik} = |\theta_i - \theta_k|$
    - $w_{ik} = \max\bigl(0, 1 - \frac{d_{ik}}{\Delta\theta}\bigr)$
    - Bin value: $v_{ik} = w_{ik} |g_i|$

### 1.4 Cell Histograms
The signal is divided into contiguous cells, each of CellSize samples (CellSize = 60):

- Cell histogram for bin $k$: $H_c(k) = \sum_{i \in c} v_{ik}$

### 1.5 Block Normalization
Adjacent cells are grouped into overlapping blocks of BlockSize (BlockSize = 2, stride = 1 cell):

- Concatenated vector: $v^{(c)} = [H_c(1),...,H_c(K), H_{c+1}(1),...,H_{c+1}(K)]^T$
- L2-normalization: $\hat v^{(c)} = \frac{v^{(c)}}{\sqrt{\|v^{(c)}\|_2^2 + \varepsilon^2}}$, $\varepsilon=10^{-6}$

The feature representation for the entire 1D trace is the vertical concatenation of normalized block vectors.

## 2. Implementation Workflow

The following sequence implements HOG-1D feature extraction:

```python
# Pseudocode for HOG-1D Feature Extraction

Input: 1D signal x[1..n], CellSize=60, NumBins=K=10, BlockSize=2, ε=1e-6
Output: HOG1D feature vector Φ

1. // Gradient
for i = 2 to n-1:
    g[i] = x[i+1] - x[i-1]
g[1] = x[2] - x[1]
g[n] = x[n] - x[n-1]

2. // Orientation
for i = 1 to n:
    θ[i] = arctan(g[i])

3. // Bin centers
Δθ = π / K
for k = 1 to K:
    θ_k = -π/2 + (k-0.5)*Δθ

4. // Cell histograms
NumCells = floor(n / CellSize)
for c = 1 to NumCells:
    H[c][1..K] = 0
    for i in cell c:
        for k = 1 to K:
            d = |θ[i] - θ_k|
            w = max(0, 1 - d/Δθ)
            H[c][k] += w * |g[i]|

5. // Block normalization
Φ = []
for c = 1 to NumCells-BlockSize+1:
    v = [ H[c][1..K]; H[c+1][1..K] ]
    norm = sqrt(sum(v.^2) + ε^2)
    v̂ = v / norm
    append v̂ to Φ

return Φ
```

## 3. Experimental Parameterization

In the cited OBM depth-matching method, parameters are fixed as follows [2512.01611]:

| Parameter     | Setting        | Purpose                                   |
|---------------|---------------|-------------------------------------------|
| CellSize      | 60 samples    | Local region for histogramming            |
| NumBins (K)   | 10            | Discretization of gradient orientations   |
| BlockSize     | 2 cells       | Normalization scope; overlapping blocks   |
| ε             | $10^{-6}$     | Regularization for L2-normalization       |

Signals are typically windowed by 10–30 ft prior to HOG-1D extraction.

## 4. Signal Preprocessing and Practical Details

Edge samples are treated with one-sided difference operators. No additional smoothing or prefiltering is applied, leveraging the inherent high-pass nature of discrete differencing. The histogram voting procedure employs linear (triangular) interpolation, ensuring that orientation votes are distributed proportionally around bin centers. Overlapping blocks (stride = 1 cell) increase feature robustness against alignment artifacts at cell boundaries and improve morphological sensitivity under local texture variation.

## 5. Integration with ShapeDTW and Sequence Alignment

The HOG-1D descriptor is incorporated into the Shape Dynamic Time Warping (ShapeDTW) workflow as follows [2512.01611]:

- For each sample $x_i$, a local subsequence $x_{i-r} \ldots x_{i+r}$ of radius $r$ is passed through HOG-1D to produce
    \[
    \phi_{\rm HOG1D}(subseq(x_i,r)) = \Phi_{HOG1D}(x_{i-r}\dots x_{i+r})
    \]
- The full feature at sample $i$ concatenates the HOG-1D descriptor with the raw values:
    \[
    Feature(x_i) = [\, \phi_{\rm HOG1D}(subseq(x_i,r)),\; x_{i-r},...,x_{i+r}\, ] 
    \]
- The Euclidean distance between such descriptors defines the pairwise shape-sensitive cost matrix for DTW.

This integration yields morphologically robust depth alignment in multi-pad borehole imaging, particularly effective under shifts, scaling, and complex geological textures.

## 6. Applicability, Limitations, and Extensions

The described HOG-1D process is suitable for any one-dimensional signal where orientation dynamics are informative for downstream similarity, alignment, or classification tasks. The framework allows flexible extension by concatenating HOG-1D features with other descriptors tailored to domain-specific patterns (e.g., geological stratigraphy, fault boundaries), offering modularity in descriptor construction [2512.01611]. No explicit detrending or smoothing is applied; improvements may result from incorporating such steps where noise dominates. This suggests that for signals with significant low-frequency bias or high-amplitude outliers, further preprocessing could enhance both the interpretability and discriminative capacity of the resulting feature vectors. A plausible implication is that HOG-1D, in conjunction with ShapeDTW, can serve as a general-purpose morphological alignment tool across 1D domains beyond borehole imaging, provided parameters are adapted to the signal’s scale and dynamics.

Source: https://www.emergentmind.com/topics/histogram-of-oriented-gradients-hog1d