我的任务之一是从 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');