An easy-to-use library for skin tone classification
Project description
Skin Tone Classifier (stone)
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,
stone -i /path/to/lenna.jpg --debug
Then, you can find the processed image in ./debug
folder, e.g.,
In this image, from left to right you can find the following information:
- detected face enclosed by a rectangle.
- dominant colors.
- The number of colors depends on settings (default is 2) and their sizes depend on their proportion.
- specified color categories and the target label is enclosed by a rectangle.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for skin-tone-classifier-0.1.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa6277daaa08e14cdd777af5426bfca6e756ca4d66000be1d7fde2acf6015277 |
|
MD5 | 7d6964e4fe34531d1a85564bcd6c481a |
|
BLAKE2b-256 | fb868efbbf26aa93dbb14a4f771af029c9feb7e8acee2af78f2d2f2470bba275 |
Hashes for skin_tone_classifier-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8e39ea3a7093d56c5a34531ece091a3d73a80894bd262ca9f224c8dfeb741c |
|
MD5 | f185ff1f892d4fc0db2e2263fa577baa |
|
BLAKE2b-256 | 3378def2fd9f2ea2983e79fb96282e224ca69bf6f33ef4bfc4db5c12090d79e1 |