Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Detection Using Skin Tone Segmentation and Morphological Operations

A MATLAB-based face detection pipeline that segments skin regions using color-space thresholds derived from Thakur et al. (2011) and refines candidate regions through morphological operations and blob analysis. The system evaluates seven different color-space combinations across RGB, YCbCr, and HSV and reports IoU-based detection metrics.


Overview

This project implements a classical (non-deep-learning) approach to face detection. The core idea is straightforward:

  1. Classify every pixel as skin or non-skin using threshold rules in multiple color spaces.
  2. Clean up the resulting binary mask with morphological opening/closing and hole filling.
  3. Extract connected components (blobs) and filter them by area, aspect ratio, and eccentricity to keep only face-like regions.
  4. Evaluate detections against YOLO-format ground truth using Intersection over Union (IoU).

Seven color-space rule combinations are tested to determine which produces the best precision, recall, and F1 score.

Input Image

The sample input image (images/image1.jpg) used for evaluation:

Input Image


Methodology

Skin Color Thresholds

The pixel-level skin classification rules are adapted from:

Thakur, S., Paul, S., Mondal, A., Das, S., & Abraham, A. (2011). Face detection using skin tone segmentation. 2011 World Congress on Information and Communication Technologies, pp. 53–60. IEEE. doi:10.1109/WICT.2011.6141217

Three independent rules are defined:

Rule Color Space Conditions
A (RGB) RGB R > 50, G > 40, B > 20, max–min channel difference > 10, `
B (CbCr) YCbCr 60 ≤ Cb ≤ 130 and 130 ≤ Cr ≤ 165
C (HS) HSV 0 ≤ H ≤ 50/360 and 0.1 ≤ S ≤ 0.9

Tested Combinations

# Combination Formula
1 RGB only A
2 CbCr only B
3 HS only C
4 RGB + CbCr A ∩ B
5 RGB + HS A ∩ C
6 CbCr + HS B ∩ C
7 RGB + HS + CbCr A ∩ B ∩ C

Morphological Post-Processing

Each binary skin mask passes through:

  1. Hole filling — imfill(mask, 'holes')
  2. Opening — removes small noise (disk structuring element, radius 5)
  3. Closing — bridges narrow gaps

Blob Filtering

Connected components are accepted as face candidates only if:

  • Area ≥ 1 500 px
  • Aspect ratio (width / height) ∈ [0.4, 1.1]
  • Eccentricity ∈ [0.25, 0.97]

Evaluation

Detections are matched to ground truth bounding boxes via greedy IoU matching (threshold = 0.3). The following metric is reported:

  • Mean IoU (mIoU) over matched pairs — measures both detection correctness and bounding-box overlap quality

Note: With a single test image containing only one face, metrics like TP/FP/FN, precision, recall, and F1-score are trivially 0 or 1 and not statistically meaningful. mIoU alone is sufficient: a value of 0 means no face was detected; a positive value reflects both correct detection and localization quality.


Repository Structure

morphological-face-detection/
├── src/
│   └── main.m              # Main MATLAB script (all-in-one pipeline)
├── images/
│   └── image1.jpg           # Input test image
├── output/                  # Generated outputs (masks, results, report)
│   ├── 00_original_image.png
│   ├── 01–07_*_a_raw_mask.png
│   ├── 01–07_*_b_after_morphology.png
│   ├── 01–07_*_result.png
│   └── performance_report.txt
├── README.md
└── LICENSE

Requirements

  • MATLAB R2019b or later (Image Processing Toolbox required)
    • rgb2hsv, rgb2ycbcr, imfill, imopen, imclose, strel, regionprops

Usage

  1. Clone the repository

    git clone https://github.com/kutmur/morphological-face-detection.git
    cd morphological-face-detection
  2. Place input images in the images/ directory (a sample image1.jpg is already included).

  3. Run the pipeline from MATLAB:

    cd src
    main
  4. Check outputs in the output/ directory:

    • Individual channel visualizations (R, G, B, H, S, Cb, Cr)
    • Raw and morphologically processed skin masks for each combination
    • Detection result images (red = detected, green = ground truth)
    • performance_report.txt — summary performance table

Results

Performance on image1.jpg (IoU threshold = 0.30):

Model mIoU
RGB only (A) 0.3751
CbCr only (B) 0.0000
HS only (C) 0.3733
RGB + CbCr (A∩B) 0.3751
RGB + HS (A∩C) 0.3861
CbCr + HS (B∩C) 0.3733
RGB + HS + CbCr (A∩B∩C) 0.3861

The RGB + HS and RGB + HS + CbCr combinations achieved the highest mean IoU (0.3861), correctly detecting the face with the best localization quality.


Detection Pipeline Visualization

The figure below traces the best-performing combination — RGB + HS (A ∩ C) through each stage of the pipeline, showing how each step progressively narrows down the skin regions to a precise face bounding box.

Green box = ground truth bounding box · Red box = detected face

Stage Step Output
1 Input image — original RGB photo Original image
2 Raw skin mask (A ∩ C) — pixels classified as skin using RGB & HS rules. Includes noise and gaps. Raw skin mask (RGB+HS)
3 Morphological cleanup — hole filling, opening (radius-5 disk), and closing bridge gaps and remove small noise. After morphological cleanup (RGB+HS)
4 Final detection — connected components filtered by area (≥1 500 px), aspect ratio (0.4–1.1), and eccentricity (0.25–0.97). Red box = detection, green box = ground truth. Final detection (RGB+HS)

Stage-by-stage explanation:

  1. Skin classification — Each pixel is tested against the RGB rule (A) and the HS rule (C). Only pixels satisfying both rules are marked white. This produces a noisy binary mask with gaps and isolated specks.
  2. Morphological cleanup — Hole filling (imfill) closes interior gaps. Opening with a disk structuring element (radius 5) removes small noise specks. Closing bridges narrow gaps in the skin region, producing a smooth, solid skin blob.
  3. Blob filtering — regionprops extracts every connected component. Blobs that meet all geometric constraints (area, aspect ratio, eccentricity) are accepted as face candidates and drawn as red bounding boxes.
  4. Evaluation — Detected boxes are compared to ground-truth boxes via greedy IoU matching (threshold = 0.3). Green boxes show the ground truth.

The RGB + HS + CbCr (A ∩ B ∩ C) combination produced an equally high IoU (0.3861) and follows the identical pipeline pattern — see 07_*_a_raw_mask.png, 07_*_b_after_morphology.png, 07_*_result.png in the output/ directory.


Dataset

The test images are sourced from the Face Detection Dataset on Kaggle:

Fares Elmenshawii. Face Detection Dataset. Kaggle. https://www.kaggle.com/datasets/fareselmenshawii/face-detection-dataset

The dataset provides images with YOLO-format bounding box annotations used as ground truth for evaluation.


References

  1. S. Thakur, S. Paul, A. Mondal, S. Das, and A. Abraham, "Face detection using skin tone segmentation," 2011 World Congress on Information and Communication Technologies, pp. 53–60, Dec. 2011. doi:10.1109/WICT.2011.6141217

  2. F. Elmenshawii, "Face Detection Dataset," Kaggle. [Online]. Available: https://www.kaggle.com/datasets/fareselmenshawii/face-detection-dataset


License

This project is licensed under the MIT License — see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages