Check the Kaggle notebook
This project uses OpenCV and the LAB color space to identify colors in images for improved perceptual accuracy. Unlike the original version, this implementation works in environments without interactive display capabilities (like Kaggle notebooks).
- Grid-based Color Sampling: Automatically samples colors at evenly spaced points across the image
- Dominant Color Analysis: Uses K-means clustering to identify the most common colors in the image
- LAB Color Space Matching: Matches colors using the perceptually uniform LAB color space for better results
- No Interactive Dependencies: Works in non-interactive environments like Kaggle notebooks
- Comprehensive Color Analysis: Provides both point-based and dominant color identification
- Visualization Tools: Creates visual representations of identified colors and their distribution
- Clone the repository:
git clone https://github.com/Assem-ElQersh/Color-Identification-Lab-2.git
- Navigate to the project directory:
cd Color-Identification-Lab-2
- Install the required libraries:
pip install -r requirements.txt
- Create a new notebook on Kaggle
- Add the "colour-detection-using-pandas-opencv" dataset to your notebook
- Copy the contents of
kaggle_color_identifier.py
into your notebook - Run the notebook to analyze colors in your images
# Import the module
from color_identifier import analyze_image
# Analyze an image
analyze_image('path/to/your/image.jpg')
- Loading Color Data: The program loads a database of named colors with their RGB values
- Image Processing: The input image is loaded and processed using OpenCV
- Grid-based Sampling: Colors are sampled at regular intervals across the image
- LAB Color Matching: Each sampled color is converted to the LAB color space and matched against the database
- Dominant Color Analysis: K-means clustering identifies the most common colors in the image
- Visualization: Results are displayed using matplotlib with the original image and color information
The LAB color space consists of:
- L: Lightness from black (0) to white (100)
- a: Color from green (-) to red (+)
- b: Color from blue (-) to yellow (+)
Using LAB space for color comparison provides more perceptually accurate results than direct RGB comparison.
The program produces two types of visual outputs:
-
Grid-based Color Analysis:
- Shows the original image with sampling points
- Displays color names and RGB values for each sampled point
-
Dominant Color Analysis:
- Shows the most common colors in the image
- Displays color names, RGB values, and frequency percentages
You can modify these parameters to adjust the analysis:
# Change the number of sampling points
color_results = identify_colors_in_image(image, colors_df, num_points=7) # Default is 5
# Adjust the number of dominant colors to find
dominant_colors = analyze_dominant_colors(image, colors_df, k=8) # Default is 5
- Graphic Design: Identify color schemes from inspiration images
- Image Analysis: Extract and quantify color information from photographs
- Data Visualization: Generate color palettes based on dominant colors
- UI/UX Design: Create harmonious color schemes based on reference images
- Digital Art: Analyze color composition in artworks
- Non-interactive: Works in environments without display capabilities (like Kaggle)
- Automatic Processing: No manual clicking required to identify colors
- Comprehensive Analysis: Provides both point-based and overall color analysis
- Better Visualization: Creates clear visual representations of color information
- Robust Error Handling: Handles missing files or incorrect paths gracefully
The above image shows an example of the original project. The new implementation produces similar results but with automated color sampling.
This project is licensed under the MIT License - see the LICENSE file for details.