改进MATLAB中橙色的检测

时间:2012-08-06 11:41:17

标签: image-processing colors detection

我的任务之一是从16000张图像中检测来自蚁群的一些颜色。所以,我已经用蓝色,粉红色和绿色做得很好,但现在我需要改进橙色的检测。这对我来说有点棘手,因为我是图像处理领域的新手。我举了几个例子,我做了什么,我的问题是什么。

原始图片:http://img705.imageshack.us/img705/2257/img4263u.jpg

检测橙色:http://img72.imageshack.us/img72/8197/orangedetection.jpg

检测绿色:http://img585.imageshack.us/img585/1347/greendetection.jpg

我曾使用selectPixelsAndGetHSV.m获取HSV值,之后我使用colorDetectHSV.m来检测具有相同HSV值的像素。 你能不能给我任何想法如何提高橙色的检测能力,而不是检测周围的整只蚂蚁和巢穴?

提前谢谢!

function [K]=colorDetectHSV(RGB, hsvVal, tol)

HSV = rgb2hsv(RGB);

% find the difference between required and real H value:
diffH = abs(HSV(:,:,1) - hsvVal(1));

[M,N,t] = size(RGB);
I1 = zeros(M,N); I2 = zeros(M,N); I3 = zeros(M,N);

T1 = tol(1);

I1( find(diffH < T1) ) = 1;

if (length(tol)>1)
% find the difference between required and real S value:
diffS = abs(HSV(:,:,2) - hsvVal(2));
T2 = tol(2);
I2( find(diffS < T2) ) = 1;
if (length(tol)>2)
% find the difference between required and real V value:
difV = HSV(:,:,3) - hsvVal(3);
T3 = tol(3);
I3( find(diffS < T3) ) = 1;
I = I1.*I2.*I3;
else
I = I1.*I2;
end
else
I = I1;
end
K=~I;
subplot(2,1,1),
figure,imshow(RGB); title('Original Image');
subplot(2,1,2),
figure,imshow(~I,[]); title('Detected Areas');

1 个答案:

答案 0 :(得分:0)

您不会显示您使用的目标HSV值。这可能是问题所在。

在您提供的示例中,错误地选择了许多区域,其色调范围从30到40.这些区域对应于蚂蚁身体部位。您想要选择的橙色部分实际上具有从大约7到15的色调,并且将它们与蚂蚁区分开来应该不难。

尝试调整目标值(尤其是色调),您应该会获得更好的效果。实际上你也可以忽略亮度和饱和度,在这种情况下色调似乎已经足够了。