Filter löschen
Filter löschen

Detect different colors in RGB colorspace

1 Ansicht (letzte 30 Tage)
SARBE
SARBE am 8 Mai 2012
Hello, I am doing a project to detect different colors in RGB colorspace. If i will put an image then it should show that whether it is a red color, blue or green. Or it is any other color having combination of those colors. If i will put three or more colors in an image then it should detect those colors. I need help to do it. Please tell me if the code given below is correct. What should i do next if it is correct?
thank u...
rgbImage = imread('image.png');
% Display the original image. subplot(3, 4, 1); imshow(rgbImage); title('Original RGB Image');
% Split the original image into color bands. redBand = rgbImage(:,:, 1); greenBand = rgbImage(:,:, 2); blueBand = rgbImage(:,:, 3);
% Display them. subplot(3, 4, 2); imshow(redBand); title('Red band'); subplot(3, 4, 3); imshow(greenBand); title('Green band'); subplot(3, 4, 4); imshow(blueBand); title('Blue Band');
% Threshold each color band. redthreshold = 68; greenThreshold = 70; blueThreshold = 72; redMask = (redBand > redthreshold); greenMask = (greenBand < greenThreshold); blueMask = (blueBand < blueThreshold);
% Display them. subplot(3, 4, 6); imshow(redMask, []); title('Red Mask'); subplot(3, 4, 7); imshow(greenMask, []); title('Green Mask'); subplot(3, 4, 8); imshow(blueMask, []); title('Blue Mask');

Antworten (1)

Geoff
Geoff am 8 Mai 2012
Are you trying to detect a specific colour? All you are doing here is thresholding, and your code is going to detect anything that generally has a stronger red component than green or blue. And that'll be just about half the colours in the spectrum.
If you need to find a particular hue, you need to look at the relationship between its red, green and blue components. For example, to find an orangish colour, you might look for pixels that have R = 2*G and B = 0. But it won't be exact. You might want a tolerance of 5%:
% Note: Assume the bands have been converted to double
orangish = abs(R ./ G - 2) / 2 <= 0.05 & B <= R * 0.05;
That will give a logical true value for anything that looks orange.
If you don't know what colours you need to find or how many, you'll have to work out how similar a colour can be before it can be considered "the same", and then do some sort of clustering.
  1 Kommentar
Walter Roberson
Walter Roberson am 8 Mai 2012
There is no nice grouping that defines the named colors.
See the MATLAB File Exchange contribution by John D'Errico, dealing with Fuzzy Color identification.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by