SEPM 11 (Case Study)
SEPM 11 (Case Study)
Abstract
Color is a critical attribute in image processing and computer vision, playing a significant role in
recognition, tracking, and segmentation tasks. This paper presents a Python-based application
that detects and identifies the name of a color in an image upon user interaction. The proposed
system employs OpenCV for image manipulation and Pandas for color data handling. Upon
clicking any point in an image, the system detects the pixel's RGB value and maps it to the closest
matching color name from a predefined dataset. The implementation demonstrates the integration
of computer vision techniques with real-time user interaction, offering practical utility for
educational, design, and accessibility applications.
Keywords
Color Detection, Computer Vision, OpenCV, Python, Pandas, RGB, Image Processing, Dataset
Matching
I. Introduction
Color recognition is a foundational task in various domains such as image editing, digital design,
robotics, and accessibility tools for the visually impaired. Humans can recognize and name colors
easily, but training machines to do the same requires the interpretation of pixel values and
comparison with predefined color names. This project addresses this challenge by building a
desktop application using Python libraries to recognize and display color names based on user
clicks within an image.
The growing accessibility of powerful libraries such as OpenCV and Pandas makes it possible to
develop such intuitive tools with minimal resources. This paper explores the implementation of a
simple yet effective color detection application that utilizes a color dataset to recognize color
names by matching RGB values.
III. Methodology
A. Dataset
The dataset used contains 865 color entries, each with a unique name, hexadecimal code, and
RGB values. It serves as a reference point for identifying colors. This dataset is processed using
the Pandas library, which allows efficient searching and matching operations.
B. Tools and Technologies
• Python 3.x: The programming language used.
• OpenCV: Utilized for image processing tasks including image loading and mouse event
handling.
• Pandas: Used for loading and handling the CSV file containing color data.
• NumPy: Employed for numerical operations like calculating Euclidean distance.
C. Algorithm
1. Image Loading: The input image is loaded using OpenCV’s cv2.imread() function.
2. Mouse Callback Function: A function is registered to capture (x, y) coordinates on
double-click.
3. Pixel Color Retrieval: The pixel's RGB value is fetched using the image matrix.
4. Distance Calculation: Euclidean distance is calculated between the clicked RGB values
and each entry in the dataset.
5. Name Mapping: The minimum distance identifies the closest matching color name.
6. Display: The color name and its RGB values are displayed on the image near the clicked
point.
IV. Results and Discussion
The application accurately detects colors for a wide range of images under standard lighting
conditions. Testing with various images showed that the color names displayed were sufficiently
accurate for practical usage.
However, the precision of color matching is dependent on the dataset. Some perceptually similar
colors may map to names that are not intuitively expected by users. Enhancing the dataset with
more descriptive or human-perceived color names could improve the user experience.
Furthermore, lighting and image quality can affect the perceived color, though this project works
reliably with standard digital images.
V. Applications
• Graphic Design: Identifying and matching color tones.
• Educational Tools: Teaching color theory and computer vision basics.
• Accessibility: Assisting color-blind users in identifying colors.
• Image Analysis: Used in research and visual content curation.
VI. Conclusion
The proposed system offers a lightweight and effective method for real-time color detection using
Python. By combining image processing techniques with a structured dataset, the tool can assist
users in quickly identifying colors within any digital image. The approach is extendable and can
serve as a base for more complex computer vision applications.
References
[1] Bradski, G. "The OpenCV Library." Dr. Dobb’s Journal of Software Tools, 2000.
[2] McKinney, W. "Data Structures for Statistical Computing in Python." Proceedings of the 9th
Python in Science Conference, 2010.
Color Detector Using Python
Program:
import cv2
import numpy as np
import pandas as pd
import argparse
#Reading csv file with pandas and giving names to each column
index=["color","color_name","hex","R","G","B"]
csv = pd.read_csv('colors.csv', names=index, header=None)
#function to calculate minimum distance from all colors and get the most matching color
def getColorName(R,G,B):
minimum = 10000
for i in range(len(csv)):
d = abs(R- int(csv.loc[i,"R"])) + abs(G- int(csv.loc[i,"G"]))+ abs(B- int(csv.loc[i,"B"]))
if(d<=minimum):
minimum = d
cname = csv.loc[i,"color_name"]
return cname
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_function)
while(1):
cv2.imshow("image",img)
if (clicked):
#cv2.rectangle(image, startpoint, endpoint, color, thickness)-1 fills entire rectangle
cv2.rectangle(img,(20,20), (750,60), (b,g,r), -1)
#cv2.putText(img,text,start,font(0-7),fontScale,color,thickness,lineType )
cv2.putText(img, text,(50,50),2,0.8,(255,255,255),2,cv2.LINE_AA)
clicked=False
cv2.destroyAllWindows()
Output:
Open command prompt from the project folder itself.