Color detection and display its name
Show older comments
Color detection project
- take colors in circles or squares
- print it
- take a photo of this print
- then put it in your code for color detection
- It should be able to display the name of that color
I have started this project with very simple concept of masking. But colors exists in hundreds or thousands of shades. In my project code should be able to detect any shade and any color. I am thinking to use the concept of Euclidean distance to find the distance of color from origin, but i can not really do it.
If someone could help me please post your solution.
Here is the code i used. it detects only four colors but from one image only.
%------------------------------------
% Read the image into an array.
filename=input('Input the filename of the image>');
RGB = imread(filename);
RGB = imread('D:\College\Project\Project\Cube.png');
%------------------------------------
% Display the original image.
subplot(2, 3, 1);
imshow(RGB);
title('Original RGB Image');
yellowMask = colorDetectHSV(RGB, [0.2 0.9 0], [0.05 0.05 0.05]);
redMask =colorDetectHSV(RGB, [1 1 1], [0.1 0.2 0.2]);
blueMask =colorDetectHSV(RGB, [0.6 0.5 0.6], [0.2 0.3 0.4]);
% Or can try this for blue color:
% blueMask =colorDetectHSV(RGB, [1 0.5 0], [0.4 0.4 0.3]);
greenMask =colorDetectHSV(RGB, [0.369 0.786 0.769], [0.2 0.2 0.2]);
% Display them.
subplot(2, 3, 2);
imshow(yellowMask);
title('Yellow Mask');
subplot(2, 3, 3);
imshow(greenMask);
title('Green Mask');
subplot(2, 3, 4);
imshow(blueMask);
title('Blue Mask');
subplot(2, 3, 5);
imshow(redMask);
title('Red Mask');
3 Comments
Christian Lenz
on 20 Jul 2012
I don't quite well understand your question... Every color has allready a specific value in your RGB-image. Try:
RGBimg = imread( ... );
RGBimg = double( RGBimg );
Rimg = RGBimg ./ max(max(max( RGBimg ) ) );
SARBE
on 22 Jul 2012
Walter Roberson
on 22 Jul 2012
Did you look at the work of John D'Errico, or of Image Analyst ?
Answers (2)
Walter Roberson
on 20 Jul 2012
1 vote
Euclidean distance is not enough. Look in the File Exchange for John D'Errico's Fuzzy Color Detection.
But if your task really is to "detect any shade and any color", you should consider giving up before you start any development. Seriously. What you want to do cannot reliably be done. There is no scientific definition for what each color is, or where one shade ends and another begins. And color perception is personal, not absolute. See http://blog.xkcd.com/2010/05/03/color-survey-results/
Image Analyst
on 21 Jul 2012
1 vote
I have several color detection applications in my File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Each uses a different method. Feel free to adapt any of them.
5 Comments
Navodita Das
on 12 May 2020
Above file exchanges are very useful, thank you for that.
Is it possible to set and reference axes in image and find the color point's coordinates axis w.r.t. reference axes.
like we enter an image-
and matlab will set the reference axes on its own

then
will get the coordinates of color points w.r.t the ref. axis.

to get (x,y) of green,blue.
is it possible to get?
Image Analyst
on 12 May 2020
Sure, just subtract the x and y coordinates of the origin from any other x and y coordinates you get. Be careful not to get confused with thinking (x,y) is how you index an image. Images are matrices and are indexed (row, column) which is (y, x), NOT (x, y).
Navodita Das
on 13 May 2020
Ok, thank you.
Navodita Das
on 20 May 2020
Suppose, an image contains red point in it. Can I set that red point as origin of coordinate system?
Image Analyst
on 20 May 2020
Yes, of course.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!