필터 지우기
필터 지우기

Red object detection picking up yellow color.

조회 수: 1 (최근 30일)
Adam Hicks
Adam Hicks 2017년 12월 13일
편집: Adam Hicks 2017년 12월 13일
Part of my program isolates the red objects in an image and displays them in a binary image. It works well but has been including yellow objects which is an issue. I've tried adjusting the values in my code with no luck.
img = imread(imname);
gimg = rgb2gray(img);
red = imsubtract(img(:,:,1), gimg);
red = medfilt2(red, [4 4]);
red = im2bw(red, 0.15);
redObjects = bwareaopen(red, 200);
The red objects in my image are all exactly [1 0 0]. Is there a way to do this with hsv that might be more accurate or am I missing something simple here?

채택된 답변

John D'Errico
John D'Errico 2017년 12월 13일
편집: John D'Errico 2017년 12월 13일
You extracted ONLY the red channel. Then you looked for red colors. But there are other colors which have the red channel maxxed out, yet are not red. Color is THREE dimensional. If you ignore the other two channels, expect to fail at your task. Your methodology would have found the [1 1 0] color too, calling it "red".
If your goal is to find ONLY colors which are explicitly and exactly [1 0 0], then use tools that can do so.
  댓글 수: 2
Adam Hicks
Adam Hicks 2017년 12월 13일
I understand what I need to do now, but I'm not sure which functions to use at this point. I'll replace rgb2gray and imsubtract in my code with a method of isolating [1 0 0] or [255 0 0] without ignoring green and blue. I'll use color thresholding/masking to do this. A point in the right direction would be helpful. Thanks for the answer.
Adam Hicks
Adam Hicks 2017년 12월 13일
편집: Adam Hicks 2017년 12월 13일
Here is what I have working for anyone with a similar problem:
img = imread(imname);
red = img(:,:,1);
green = img(:,:,2);
blue = img(:,:,3);
rMask = red > 200;
gMask = green < 50;
bMask = blue < 50;
redObjectMask = uint8(rMask & gMask & bMask);
isored = zeros(size(redObjectMask),'uint8');
isored(:,:,1) = img(:,:,1) .* redObjectMask;
isored(:,:,2) = img(:,:,2) .* redObjectMask;
isored(:,:,3) = img(:,:,3) .* redObjectMask;
bwImage = im2bw(isored,0);

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by