Blob Detection on Color Image

12 visualizzazioni (ultimi 30 giorni)
Sam Van Lommel
Sam Van Lommel il 25 Mar 2019
Risposto: Image Analyst il 26 Mar 2019
For our bachelor thesis we have to collect colored ducks with a robot arm. For the visual aspect, we first have to do a segmentation of the different colors, and count the amount of ducks of each color (e.g. blue, green, red, yellow ducks).
We can currently seperate a color by choice (using HSV color space and thresholds on the hue values) and calculate the center point of a certain colored duck. The problem happens when there's two ducks of the same color. Then we cannot calculate the center point.
We use this image called 'Ducks.jpg'
Ducks.jpg
Below you can find our Matlab-code. And below that the result if we run this code searching for the center point of the magenta duck.
I = imread('Ducks.jpg')
function [xCenter,yCenter] = FunctieMiddenBepalen(I)
%Set thresholds of HSV
sThresh = [0.5 1];
vThresh = [0.1 1];
%Rgb2HSV conversion
hsvI = rgb2hsv(I);
hueI = round(hsvI(:,:,1)*360);
satI = hsvI(:,:,2);
valI = hsvI(:,:,3);
threshI = (satI>=sThresh(1))&(satI<=sThresh(2))&(valI>=vThresh(1))&(valI<=vThresh(2));
%Determine Color thresholds
black = (valI<vThresh(1));
white = (satI<sThresh(1))&(valI>=vThresh(1));
red = ((hueI<=30)|(hueI>330))&threshI;
yellow = ((hueI>30)&(hueI<=90))&threshI;
green = ((hueI>90)&(hueI<=150))&threshI;
cyan = ((hueI>150)&(hueI<=210))&threshI;
blue = ((hueI>210)&(hueI<=270))&threshI;
magenta = ((hueI>270)&(hueI<=330))&threshI;
%Set color of which we want to determine the center point
hsvI(blue)=0;
hsvI(white)=0;
hsvI(red)=0;
hsvI(yellow)=0;
hsvI(green)=0;
hsvI(cyan)=0;
hsvI(magenta)=1;
%Determine x and y value of searched object
[ yValues,xValues ] = find( hsvI==1 );
%Calculate center point
xCenter = median(xValues);
yCenter = median(yValues);
end
%Here we plot a black dot in the center of the duck
figure(1)
image(I);
hold on
plot(xCenter,yCenter , 'o' , 'MarkerFaceColor' , 'k');
hold off
Gives the following result:
55649742_267125464176981_5441708806524370944_n.jpg
The problem occurs when we try to calculate the center point of the green duck, because there are two of them in this picture. Also we're looking for a way to calculate the amount of ducks from each color. We are looking into blobdetection methods, but can't seem to figure this out..
Help is very welcome!
Kind regards

Risposte (1)

Image Analyst
Image Analyst il 26 Mar 2019
You need to use regionprops(). First, compute the color difference - it's probably easiest if you use rgb2lab() rather than rgb2hsv(). Then use sqrt() to compute DeltaE = sqrt((meanL - refL)^2+(meanA-refQ)^2+(meanB-refB)^2). This will tell you what the nearest reference color is to each of your ducks. First get a binary image of the ducks - I assume you know how to do that - let's call it mask. Then, something like (untested)
labeledImage = bwlabel(mask);
labImage = rgb2lab(rgbImage);
lImage = labImage(:,:,1);
aImage = labImage(:,:,2);
bImage = labImage(:,:,3);
% Get mean and centroid for each color channel
lprops = regionprops(mask, lChannel, 'MeanIntensity', 'Centroid');
lMeans = [lprops.MeanIntensity]; % Array of 5 L values.
centroids = vertcat([lprops.Centroid]); % Array of 5 rows (one for each duck) by 2 columns (x and y).
% Same for aprops and bprops to get the mean a, and mean b for each duck.
aprops = regionprops(mask, aChannel, 'MeanIntensity', 'Centroid');
aMeans = [lprops.MeanIntensity]; % Array of 5 a values.
bprops = regionprops(mask, bChannel, 'MeanIntensity', 'Centroid');
bMeans = [lprops.MeanIntensity]; % Array of 5 b values.
You don't need to compute the centroids for the a and b channel since they will be the same as for the L channel.
centroids will be an array with two columns (x and y) and one row for each duck.
Then get the delta E's to determine which reference color is closest to each duck.
Let me know of any difficulties.

Categorie

Scopri di più su Agriculture in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by