MATLAB: How to detect specific colors

colorimage processingImage Processing ToolboxMATLAB

I need to build an application which takes an image of a clothing article and tells whether its colored black,blue, beige, or brown.
I concluded a method to detect whether the color is blue or not by taking the minimum value for each channel and incase the blue has the greater value I could say its a blue article but incase this method got applied on a black clothing article, it may identify it as blue which is wrong.
So how can I differ between these four colors (black,blue,beige,brown)?

Best Answer

Use rgb2lab() to convert your images to LAB color space. Then use it again to find the lab values for your reference colors. Then compute the delta E (color difference) between your image and each of the reference colors. Which ever one is lowest is the color class that pixel belongs to.