I'm working on a program in matlab to detect an object in a sequence of images. The object I'm trying to detect a red ball.
First, I tried to use thresholding to segment the ball from the image, but I couldn't do that. I couldn't get rid of the shadow under the ball. Any Ideas how to get rid of the small part under the ball?
My second question is, I want to make sure that the object I'm looking for is a red ball. my code will detect any red object, I want to make sure its a circle.
My code:
I1 = imread('images/B1.jpg'); % read image
ID1 = im2double(I1); % convert to double
IDG1 = rgb2gray(ID1); % conver to gray scale
t = 112; % set a thresholding value
IT = im2bw(IDG1, t/255); % apply the threshold
I2 = ~IT; % get a nigative image
I3 = bwareaopen(I2,40); % get rid of small unwanted pixels
I4 = imclearborder(I3); % clear pixels of the borders
I5 = bwareaopen(I4,60); % get rid of small unwanted pixels
I6 = imfill(I5,'holes'); % fill the gap on the ball top part
I7 = imclearborder(I6); % get rid of small unwanted pixels
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…