Documentation Index
Fetch the complete documentation index at: https://mintlify.com/soymatudev/Pokedex-Fleek/llms.txt
Use this file to discover all available pages before exploring further.
Overview
PokéDex Fleek uses a color-based matching algorithm to identify Pokémon from real-world objects. When you scan an object with your camera, the app extracts its dominant color and finds the closest Pokémon match using mathematical color distance calculations.The algorithm prioritizes perceptual accuracy over raw RGB values by using HSL (Hue, Saturation, Lightness) color space for matching.
Color Distance Formula
Euclidean Distance in 3D Space
The core of the matching algorithm is the Euclidean distance formula applied to RGB color components: Where:- = RGB values of the scanned object
- = RGB values of each Pokémon in the database
- = Distance between the two colors (lower = more similar)
ColorService Implementation
Here’s the actual implementation from the codebase:src/services/ColorService.js
How It Works
- Calculate distances: Compare the scanned color against every Pokémon’s RGB values
- Track minimum: Keep track of the smallest distance found
- Return match: The Pokémon with the smallest distance is the best match
Why HSL Color Space?
While we calculate distance in RGB space, we convert colors to HSL for initial matching because:| Advantage | Explanation |
|---|---|
| Perceptual Accuracy | HSL aligns better with how humans perceive color similarity |
| Brightness Independence | Hue remains consistent across different lighting conditions |
| Simplified Matching | Color families (red, blue, green) are grouped by hue ranges |
| Better UX | Reduces false positives from lighting variations |
Hex to Hue Conversion
Before color matching, we extract the hue component from the detected color:src/features/scanner/ScannerScreen.js
Conversion Steps
Step-by-Step Matching Process
1. Capture Image
2. Extract Dominant Color
3. Convert to Hue
4. Find Matching Pokémon
Each Pokémon in the database has a predefined hue range. For example:
- Charmander: 0-30° (red-orange)
- Squirtle: 180-240° (blue-cyan)
- Bulbasaur: 90-150° (green)
Color Range Examples
Visual Hue Wheel
Example Pokémon Ranges
Fire Types
Hue Range: 0-30°Charmander, Vulpix, GrowlitheMatches red, orange, and warm tones
Water Types
Hue Range: 180-240°Squirtle, Psyduck, MagikarpMatches blue and cyan colors
Grass Types
Hue Range: 90-150°Bulbasaur, Oddish, BellsproutMatches green and lime tones
Mathematical Deep Dive
Why Euclidean Distance?
The Euclidean distance is a natural choice because:- Symmetry: Distance from A to B equals distance from B to A
- Triangle Inequality: Direct path is always shortest
- Computational Efficiency: Simple square root operation
- Intuitive: Matches human understanding of “closeness”
Alternative Approaches
CIELAB Color Space
CIELAB Color Space
Mentioned in the README as a future enhancement. CIELAB is designed to approximate human vision more closely than RGB:This would provide even more perceptually accurate matching.
Manhattan Distance
Manhattan Distance
Sum of absolute differences instead of squared differences:Faster to compute but less accurate for color perception.
Weighted RGB
Weighted RGB
Account for human eye sensitivity to different colors:Green is weighted higher because humans are most sensitive to it.
Performance Optimizations
Hue Pre-filtering
Instead of calculating Euclidean distance for all 151 Pokémon, we first filter by hue range, reducing comparisons by ~80%
Code Example: Full Flow
Here’s how everything comes together inScannerScreen.js:
Next Steps
AI Detection
Learn how TensorFlow.js enhances color matching with object classification
Camera Integration
Explore the camera setup and frame processing pipeline