Skip to main content

An easy-to-use library for skin tone classification

Project description

Skin Tone Classifier (stone)

PyPI - Python Version PyPI GitHub release (latest by date including pre-releases) License: GPL v3

An easy-to-use library for skin tone classification.

This can be used to detect face or skin area in the specified images. The detected skin tones are then classified into the specified color categories. The library finally generates results to report the detected faces (if any), dominant skin tones and color category.


Installation

To install SkinToneClassifier:

pip install skin-tone-classifier

HOW TO USE

Quick Start

Given the famous photo of Lenna, to detect her skin tone,

Lenna picture
just run:
stone -i /path/to/lenna.jpg --debug

Then, you can find the processed image in ./debug folder, e.g.,

processed Lenna picture

In this image, from left to right you can find the following information:

  1. detected face enclosed by a rectangle.
  2. dominant colors.
    1. The number of colors depends on settings (default is 2) and their sizes depend on their proportion.
  3. specified color categories and the target label is enclosed by a rectangle.
  4. you can find a summary text at the bottom.

Furthermore, there will be a report file named result.csv which contains more detailed information, e.g.,

file face_location dominant_1 props_1 dominant_2 props_2 category distance(0-100)
lena_std 84:153 #CB6268 0.51 #E1A299 0.49 #e7c1b8 17.37

Detailed Usage

To see the usage and parameters, run:

stone -h

Output in console:

usage: stone [-h] [-i IMAGE FILENAME [IMAGE FILENAME ...]]
               [-c COLOR [COLOR ...]] [-d] [-o DIRECTORY] [--n_colors N]
               [--new_width WIDTH] [--scale SCALE] [--min_nbrs NEIGHBORS]
               [--min_size WIDTH [HEIGHT ...]]

Skin Tone Classifier

optional arguments:
  -h, --help            show this help message and exit
  -i IMAGE FILENAME [IMAGE FILENAME ...], --images IMAGE FILENAME [IMAGE FILENAME ...]
                        Image filename(s) to process;
                        supports multiple values separated by space, e.g., "a.jpg b.png";
                        supports directory or file name(s), e.g., "./path/to/images/ a.jpg";
                        The app will search all images in the directory of this script in default.
  -c COLOR [COLOR ...], --categories COLOR [COLOR ...]
                        Skin tone categories; supports RGB hex value leading by # or RGB values separated by comma(,).
  -d, --debug           Whether to output processed images, used for debugging and verification.
  -o DIRECTORY, --output DIRECTORY
                        The path of output file, defaults to the directory of this script.
  --n_colors N          CONFIG: the number of dominant colors to be extracted, defaults to 2.
  --new_width WIDTH     CONFIG: resize the images with the specified width, defaults to 200.
  --scale SCALE         CONFIG: how much the image size is reduced at each image scale, defaults to 1.1
  --min_nbrs NEIGHBORS  CONFIG: how many neighbors each candidate rectangle should have to retain it.
                                Higher value results in less detections but with higher quality.
  --min_size WIDTH [HEIGHT ...]
                        CONFIG: minimum possible face size. Faces smaller than that are ignored, defaults to "30 30".

Use Cases

1. To process multiple images

1.1 Multiple filenames

stone -i (or --images) a.jpg b.png

1.2 Images in some folder(s)

stone -i ./path/to/images/

NB: Supported image formats: .jpg, .gif, .png, .jpeg, .webp, .tif.

In default (i.e., stone without -i option), the app will search images in current folder.

2. To specify color categories

2.1 Use hex values

stone -c (or --categories) #373028 #422811 #fbf2f3

NB: Values start with '#'.

2.2 Use RGB tuple values

stone -c 55,48,40 66,40,17 251,242,243

NB: Values split by comma ',', multiple values are still separated by space.

3. Specify output folder

The app puts the final report (result.csv) in current folder in default.

To change the output folder:

stone -o (or --output) ./path/to/output/

The output folder will be created if it does not exist.

In result.csv, each row is showing the color information of each detected face. If more than one faces are detected, there will be multiple rows for that image.

4. Store processed image for debugging

stone -d (or --debug)

This option will store the processed image (like the Lenna example above) in ./path/to/output/debug folder.

By default, to save space, the app does not store processed images.

Like in the result.csv file, there will be more than one processed images if 2 or more faces were detected.

5. Tune parameters of face detection

The rest parameters of CONFIG are used to detect face. Please refer to https://stackoverflow.com/a/20805153/8860079 for detailed information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skin-tone-classifier-0.1.7.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skin_tone_classifier-0.1.7-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file skin-tone-classifier-0.1.7.tar.gz.

File metadata

  • Download URL: skin-tone-classifier-0.1.7.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for skin-tone-classifier-0.1.7.tar.gz
Algorithm Hash digest
SHA256 71488cd54abcf8c6293d9ab4d23177748f03fc4fdd69b953476c35a415be8eb8
MD5 2a801d7320d05b77d8e5c3ed59560935
BLAKE2b-256 ffed6ade0b12b0b191289ea0d3ce8d043d223f0f84d8f17f44ee8cf5635bd45c

See more details on using hashes here.

File details

Details for the file skin_tone_classifier-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for skin_tone_classifier-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5f865f1aaca9fbfd4cab5138fd0912cffcac7d4cd341e3d6d74d90c9d52fe7ec
MD5 7c2d410f531137e0cd2e36228d928133
BLAKE2b-256 4855b6edb65b35a23877a9ec62e2259cf2d4a3c6e5d7258542e2d49d302442ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page