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

5 views (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 27 Nov 2015
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"
  2 Comments
chadi fahmi
chadi fahmi on 27 Nov 2015
Thank u for replyin but what do u mean by reference ? u mean that i must get the average, hist and some other properties for some taken images before and save it in a database and then compare the new images with the ones that are in daatabase?? Thanks in advance.
Image Analyst
Image Analyst on 27 Nov 2015
Let's say that you've segmented your image into regions - maybe 1 or maybe more. Let's say you've identified moving objects by the magnitude of their optical flow and now have a binary image mask. So you can convert to lab and then get the means like this:
lab = rgb2lab(rgbImage);
lImage = lab(:, :, 1);
aImage = lab(:, :, 2);
bImage = lab(:, :, 3);
% Get means
meanL = mean2(lImage);
meanA = mean2(aImage);
meanB = mean2(bImage);
So now you have the mean L, A, and B. Let's say that the values are 75, 10, and -4. So how do you know if those values are closest to orange, purple, gray, or green? Well to know that, you'd have to know the LAB values of those reference colors.
Once you know the mean LAB values of orange, purple, gray, and green, then you can compare the LAB values you have (75,10,04) to the LAB values of orange, purple, gray, and green to see which of those colors is closest (i.e., the smallest distance).

Sign in to comment.

More Answers (2)

lya lya
lya lya on 28 Nov 2015
Hello,
I'm currently working on detecting colors in an image. For example, given an image that have multiple colors, and text will appear to indicate or to show each region color by displaying the color names.
I've work on HSV color space, and represent them in Fuzzy set operation.
close all; clc; clear all
img='Peppers2.bmp';
OrigImg=imread(img); % reading the image
HSVimg=(rgb2hsv(OrigImg)); % RGB->HSV conversion
Himg=(HSVimg(:,:,1)); % extracting the hue component, between [0,1]
H=(Himg*255); % normalizing to [0, 255]
% computation of the membership degree of each pixel, to each fuzzy set
RedH_l=trimf(H, [0 0 21]);
RedH_r=trimf(H, [234 255 255]);
RedH=max(RedH_l, RedH_r);
OrangeH=trimf(H, [0 21 43]);
YellowH=trimf(H, [21 43 80]);
GreenH=trapmf(H, [43 80 90 128]);
CyanH=trimf(H, [90 128 165]);
BlueH=trapmf(H, [128 165 175 191]);
PurpleH=trimf(H, [175 191 213]);
PinkH=trimf(H, [213 234 255]);
I only managed to perform the coding until here. I am not sure whether I should put in the membership function for saturation (S) and value (V) component.
For displaying image, just appear the original image and add text to indicate the color names inside the image.
Your assistance and guide are very much appreciated.

Ankith Jain Rakesh Kumar
Ankith Jain Rakesh Kumar on 3 Mar 2017
can anyone let me know how to find skin tone of a person after detecting skin from a person's body? If you have any code for it can you share it.

Categories

Find more on Recognition, Object Detection, and Semantic Segmentation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!