MATLAB: Given an image with a colored object in it i need a code to display the name of the colored object in it as a text under the image. Thanks in advance

color classificationcolor spacedelta eimage processingImage Processing Toolbox

I get an image with a camera for example then imread it and this image have a colored object it for example a green or purple ball the output should be in text under the picture for example : Purple. Please i need a matlab code for this and Thanks in advance

Best Answer

The name of the object, like you said, which would be "ball", or the name of the color, like you also said, which would be "purple"?
Basically you need to define certain reference colors that you expect to encounter, like purple, green, or whatever. Then take a picture of them with the same camera and lighting that you use to take a picture of your "test images". Now convert the images to "book formula" CIE lab with rgb2lab(). Then determine the lab of your reference colors. So now you have an LAB value triplet for each reference color.
Next you need to do the same thing with your unknown object. Then compute the color difference, called "Delta E", which can be the Euclidean distance in LAB color space. There are other more accurate methods but they're far, far more complicated and you don't need them for this situation.
delta E = sqrt((lTest-lRef)^2 + (aTest-aRef)^2 + (bTest-bRef)^2);
Do that with the mean colors for the regions, and do it for each Ref color that you want to compare against. The reference color it's closest to will be the one reference color that has the lowest Delta E.
For an example, see my "Color segmentation by Delta E color difference"
Related Question