-
Run the following command line in the terminal:
pip install opencv-python numpy webcolors matplotlib
-
Enter the path of the image from where you wish to detect the colours
-
Enter the output path for the
.txt
file -
Upon running the code it displays the colours detected in the
.txt
file
Input Image:
Output:
This project is a tool that analyzes an image to identify the most prominent colors and their closest matching names and hexadecimal codes. The detected color information is saved to a text file in a structured format for further use or reference.
- Detects the dominant colors in an image.
- Matches colors to their closest CSS3 color names and hexadecimal codes.
- Outputs the detected color information in a sorted list, ranked by prominence.
- Saves the results to a user-defined text file for easy access.
-
Image Processing:
- The image is loaded using OpenCV and converted to the RGB color space.
- The image is optionally resized for faster processing.
-
Color Detection:
- Each pixel's RGB values are compared against a predefined set of CSS3 color names and hexadecimal codes.
- The Euclidean distance is calculated to determine the closest matching color.
-
Color Aggregation: Pixels with the same color name are grouped together and their counts are summed up.
-
Results Output: The most frequent colors are ranked and saved to a text file, including their names, hexadecimal codes and occurrences.
- Input: An image file (e.g.,
.jpg
,.png
) provided via theimage_path
variable. - Output: A text file containing a sorted list of detected colors, including their names and hexadecimal codes.