This guide provides comprehensive technical documentation on how biomarkers are extracted from facial video
using remote photoplethysmography (rPPG) and computer vision techniques. The system analyzes subtle color
changes in facial skin caused by blood circulation to derive vital signs without physical contact.
Core Scientific Principle
When the heart pumps blood through the cardiovascular system, it creates periodic changes in blood volume
in the facial capillaries. These changes affect how light is absorbed and reflected by the skin, creating
measurable variations in skin color that are invisible to the naked eye but detectable through video analysis.
Beer-Lambert Law:
I = Iβ Γ e^(-Ξ΅ Γ c Γ l)
Where:
- I = Transmitted light intensity
- Iβ = Incident light intensity
- Ξ΅ = Molar extinction coefficient
- c = Concentration of chromophore (hemoglobin)
- l = Path length through tissue
Why Green Channel?
Red Channel: Less sensitive to blood volume (more affected by lighting)
Green Channel: Most sensitive to blood volume changes β
Blue Channel: Too noisy, affected by shadows
Hemoglobin in blood absorbs green light (around 550nm wavelength) more strongly than red or blue,
making it ideal for detecting blood volume changes.
favorite
Heart Rate Detection
Signal Extraction Process
Step 1: Define Regions of Interest (ROI)
We extract signals from three facial regions with weighted averaging:
// For each ROI, extract average green channel value
for (let i = 0; i < pixels.length; i += 4) {
greenSum += pixels[i + 1]; // Green channel at index 1
pixelCount++;
}
averageGreen = greenSum / pixelCount;
// Weight and combine signals from all ROIs
weightedSignal = forehead * 0.5 + leftCheek * 0.25 + rightCheek * 0.25;
Step 3: Signal Detrending
Remove slow baseline drift caused by lighting changes or movement:
y_detrended(t) = y(t) - (a Γ t + b)
Where a (slope) and b (intercept) are computed using least squares:
a = Ξ£((t - tΜ)(y - Θ³)) / Ξ£((t - tΜ)Β²)
b = Θ³ - a Γ tΜ
Step 4: Bandpass Filtering
Apply Butterworth filter to isolate heart rate frequencies:
// Butterworth bandpass filter
Passband: 0.5 Hz to 3.0 Hz
Why: Human heart rate is typically 30-180 BPM (0.5-3.0 Hz)
- Removes high-frequency noise
- Removes low-frequency drift
- Isolates cardiac frequency range
Step 5: FFT Analysis
Convert time-domain signal to frequency domain to identify heart rate:
X(k) = Ξ£(n=0 to N-1) x(n) Γ e^(-j2Οkn/N)
// Find dominant frequency in HR range
peakFrequency = findPeakInRange(powerSpectrum, 0.5, 3.0)
// Convert to BPM
heartRate = peakFrequency Γ 60
Signal Quality Metrics
SNR = 10 Γ logββ(P_signal / P_noise)
Where:
- P_signal = Power at peak frequency
- P_noise = Average power in high frequencies (> 4 Hz)
Confidence Score Components:
- SNR > 3 dB: +25%
- Peak prominence > 0.5: +25%
- Valid RR count > 10: +25%
- Motion score < 0.3: +25%
timeline
Heart Rate Variability (HRV)
What is HRV?
HRV measures the variation in time between heartbeats. Higher HRV generally indicates:
Better cardiovascular fitness
Lower stress levels
Better autonomic nervous system balance
Greater physiological resilience
RMSSD Calculation
Root Mean Square of Successive Differences (RMSSD) is the most common time-domain HRV metric:
RMSSD = β(1/(N-1) Γ Ξ£(RRα΅’ββ - RRα΅’)Β²)
Where:
- RRα΅’ = Time interval between successive R-peaks (in ms)
- N = Number of RR intervals
Peak Detection Algorithm
// 1. Calculate R-R intervals (time between peaks)
rrIntervals = []
for (i = 1; i < peaks.length; i++) {
interval = peaks[i].time - peaks[i-1].time
rrIntervals.push(interval * 1000) // Convert to milliseconds
}
// 2. Filter outliers (physiologically invalid intervals)
validIntervals = rrIntervals.filter(rr =>
rr > 300 && rr < 2000 // 30-200 BPM range
)
// 3. Calculate successive differences
differences = []
for (i = 1; i < validIntervals.length; i++) {
diff = validIntervals[i] - validIntervals[i-1]
differences.push(diff)
}
// 4. Calculate RMSSD
squaredDiffs = differences.map(d => d * d)
meanSquaredDiff = average(squaredDiffs)
RMSSD = Math.sqrt(meanSquaredDiff)
// 5. Clamp to reasonable range
HRV = clamp(RMSSD, 15, 100) // milliseconds
Normal HRV Ranges (RMSSD)
Population
Typical Range
Notes
Healthy Adults
20-80 ms
Varies with age and fitness
Athletes
50-100 ms
Higher is better
Stressed/Unfit
10-30 ms
Lower indicates strain
Age Factor
-3-5% per decade
Natural decline with age
air
Respiratory Rate Detection
Respiratory Signal Sources
1. Respiratory Sinus Arrhythmia (RSA)
Heart rate naturally increases during inhalation and decreases during exhalation.
This modulation appears as a low-frequency component (0.15-0.4 Hz) in the HRV signal.
2. Baseline Wandering
Breathing causes thoracic pressure changes that affect venous return,
creating slow oscillations in the PPG baseline.
Extraction Method
// Extract respiratory rate from PPG or HRV signal
function extractRespiratoryRate(signal) {
// Apply bandpass filter (0.15-0.4 Hz for 9-24 breaths/min)
filtered = bandpassFilter(signal, 0.15, 0.4);
// Compute FFT
spectrum = FFT(filtered);
// Find peak in respiratory frequency range
peak_freq = findMaxPower(spectrum, 0.15, 0.4);
// Convert to breaths per minute
respiratory_rate = peak_freq * 60;
return respiratory_rate;
}
Normal Respiratory Rates
Category
Rate (breaths/min)
Resting Adult
12-20
During Exercise
20-30+
Meditation/Sleep
8-12
psychology
Stress Level Assessment
Physiological Basis
Stress activates the sympathetic nervous system, causing measurable changes in:
Decreased HRV (reduced vagal tone)
Increased heart rate
Altered breathing patterns
Changes in peripheral blood flow
Stress Indicators
Metric
Low Stress
Medium Stress
High Stress
HRV (RMSSD)
> 50 ms
30-50 ms
< 30 ms
Heart Rate
60-70 BPM
70-85 BPM
> 85 BPM
Respiratory Rate
12-16 br/min
16-20 br/min
> 20 br/min
face
Demographics & Skin Tone Analysis
Face Detection: MediaPipe Face Mesh
Using Google's MediaPipe to detect 468 3D facial landmarks in real-time:
Using Face-API.js (Vladimir Mandic fork) with pre-trained neural networks:
Age Estimation
Architecture: ResNet-50 backbone
Training data: IMDB-WIKI dataset (500k+ faces)
Accuracy: Mean Absolute Error Β±3.5 years
Gender Classification
Architecture: MobileNetV2
Binary classification (male/female)
Training accuracy: 96.8%
Skin Tone Analysis (ITA Method)
ITA Calculation
ITAΒ° = [Arc Tangent((L* - 50) / b*)] Γ (180 / Ο)
Where:
- L* = Lightness in CIELAB color space (0-100)
- b* = Yellow-blue axis (-128 to +127)
Classification:
Very Light: ITA > 55Β°
Light: 41Β° < ITA β€ 55Β°
Intermediate: 28Β° < ITA β€ 41Β°
Tan: 10Β° < ITA β€ 28Β°
Brown: -30Β° < ITA β€ 10Β°
Dark: ITA β€ -30Β°
Fitzpatrick Scale Mapping
function itaToFitzpatrick(ita) {
if (ita > 55) return "Type I"; // Always burns, never tans
if (ita > 41) return "Type II"; // Usually burns, tans minimally
if (ita > 28) return "Type III"; // Sometimes burns, tans uniformly
if (ita > 10) return "Type IV"; // Burns minimally, tans well
if (ita > -30) return "Type V"; // Rarely burns, tans deeply
return "Type VI"; // Never burns, deeply pigmented
}
code
Technical Implementation Details
System Architecture
Class: BiomarkerAnalyzer
βββ Camera Management
β βββ getUserMedia() - Access camera stream
β βββ setupCamera() - Configure video parameters
β
βββ Face Detection Pipeline
β βββ MediaPipe Face Mesh - 468 landmarks @ 30 FPS
β βββ Face-API.js - Demographics @ 0.5 FPS
β βββ Landmark smoothing - 5-frame weighted average
β
βββ Signal Processing
β βββ ROI extraction - Green channel averaging
β βββ Detrending - Linear regression removal
β βββ Filtering - Butterworth bandpass (0.5-3.0 Hz)
β βββ FFT analysis - Frequency domain conversion
β
βββ Visualization
βββ Canvas overlay - Real-time face mesh
βββ Chart.js - Signal plots
Buffer Management
// Circular buffer for PPG signal
// Typical: 150 frames (5 seconds at 30 FPS)
ppgBuffer = new Float32Array(150);
// Store green channel values over time
ppgBuffer[index] = weightedGreenValue;
index = (index + 1) % bufferSize;
Performance Optimizations
WebAssembly Acceleration
MediaPipe uses WASM for CPU-intensive landmark detection, achieving 30+ FPS on mobile devices
GPU Delegation
Face mesh rendering uses WebGL for hardware acceleration
Adaptive Quality
Dynamically adjusts processing based on device capabilities
Deep Learning Review (2024): "Deep learning and remote photoplethysmography powered advancements in contactless physiological measurement"
Frontiers in Bioengineering
Comprehensive Review (2024): "A comprehensive review of heart rate measurement using remote photoplethysmography and deep learning"
PMC12181896
Face Regions Study (2025): "The role of face regions in remote photoplethysmography for contactless heart rate monitoring"
Nature npj Digital Medicine Key Finding: Forehead and cheeks provide best accuracy (MAE < 1.0 BPM with ML)
Phase-Shifted Method (2024): "Phase-shifted remote photoplethysmography for estimating heart rate and blood pressure"
ArXiv 2401.04560
HRV from Facial Video (2023): "Robust Heart Rate Variability Measurement from Facial Videos"
MDPI Bioengineering
Transformer Architecture (2024): "Remote physiological signal recovery with efficient spatio-temporal modeling"
Frontiers in Physiology
Open Source Libraries
MediaPipe Face Mesh - Apache License 2.0
468 3D face landmarks with iris tracking
Official Docs |
GitHub |
NPM
Face-API.js (Vladimir Mandic) - MIT License
Age, gender, emotion, and expression detection
GitHub |
NPM
Chart.js - MIT License
Data visualization for PPG signals and trends
Official Docs |
GitHub