This Python script processes facial images to extract accurate skin tone data and compute the ITA (Individual Typology Angle), which is widely used in dermatology and cosmetics to determine skin undertone.
🔍 Key Components:
- Histogram Equalization (Optional)
run_histogram_equalization(img_bgr) Enhances contrast in the image’s luminance channel to normalize lighting conditions. 2. Skin Segmentation
segment_skin(img_bgr) Uses a combination of HSV and YCrCb color space thresholds to isolate skin pixels. Non-skin areas are masked out (set to black). 3. Average Skin RGB Extraction
mask = (img_bgr[:, :, 0] > 0) | ... Averages RGB values only across the detected skin regions. Prevents background or non-skin pixels from skewing the analysis. 4. ITA Calculation
compute_ita(r, g, b) Converts the RGB skin tone to the CIE LAB color space. Computes the ITA angle, which helps categorize the skin tone on a scientific scale:
55°: Very Light 41–55°: Light 28–41°: Intermediate 10–28°: Tan -30–10°: Brown <-30°: Dark
- CLI Usage
python foundatone.py path/to/image.jpg Returns the red, green, and blue values as JSON. Saves a segmented_skin_image.png as output for visual reference. Handles errors gracefully and returns debugging info as JSON. 🧴 Use Case: Matching Foundation Shades The RGB + ITA output can be used to:
Match users with existing foundation shades. Power a foundation blender to generate custom formulas. Train a recommendation model based on historical matches and preferences.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev