필터 지우기
필터 지우기

Detect different colors in RGB colorspace

조회 수: 1 (최근 30일)
SARBE
SARBE 2012년 5월 8일
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');

답변 (1개)

Geoff
Geoff 2012년 5월 8일
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
Walter Roberson
Walter Roberson 2012년 5월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by