使用阈值处理的对象检测 [英] Object detecting using thresholding

查看:182
本文介绍了使用阈值处理的对象检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matlab中的程序来检测图像序列中的对象。我试图探测到一个红球的对象。

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.

我的代码:

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


推荐答案

也许转换图像从RGB到HSV可能是一个好主意。

Perhaps converting the image from RGB to HSV can be a good idea.

img = im2double(imread('http://i.stack.imgur.com/D3Zm7.jpg'));
imgHSV = rgb2hsv(img);

让我们显示 H 部分,其中包含唯一的颜色信息:

Let's display the H part, which contains only color information:

imshow(imgHSV(:,:,1))
colormap('hsv')
colorbar;

请注意,红色部分分布在频谱的极端。让我们尝试使用经验值对其进行阈值处理(通过查看条形图,我们可以首先猜测一些好值):

Notice the red portion is distributed at the extremes of the spectrum. Let's try thresholding it using empirical values (by looking at the bar, we can have an first guess of some "good" values):

BW = imgHSV(:,:,1) < 0.05 | imgHSV(:,:,1) > .15;

并显示结果:

imshow(BW);

不再有阴影! :)

这篇关于使用阈值处理的对象检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆