通过MatLab计算Blob的数量 [英] Counting number of Blobs via MatLab

查看:847
本文介绍了通过MatLab计算Blob的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实验MatLab图像处理方法如何工作,当我遇到这个问题。请参考下面的2张图片图片实际上是书的两侧:

I am trying to experiment how MatLab image processing methods work when I came across this problem. Please refer to the 2 images below The images are actually the sides of books:


>

右边的图像显示了绑定和计数对象数量失败的努力。代码如下:

The image on the right shows a failed effort to bound and count the number of object. The code is as follows:

BW2=~BW2;
imshow(BW2)
B = bwboundaries(BW2);
imshow(BW2)

text(10,10,strcat('\color{green}Objects Found:',num2str(length(B))))
hold on

for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2)
end

此方法采用 http://www.instructables.com/id/Image-Processing-and-Counting-using-MATLAB/step5/Find-the-边界的对象/

但是正如你可以看到,它不工作的所有时间。只有大约一半的时间,那么它会工作。有人知道我可以如何改善计数吗?或者有其他方法来计算从这样的图像blobs?

But as you can see, it doesn't work all the time. Only approximately half the time then it will work. Do anybody know how I can improve the counting? or is there another method to count blobs from an image like that?

我使用OpenCV cvBlob库成功使用了。但是当谈到MatLab,我是一个绿色的角,因此希望有人可以帮助我这个。谢谢。

I did this successfully using OpenCV cvBlob library before. But when it comes to MatLab, I am a greenhorn, hence hope somebody can assist me on this. Thanks.

推荐答案

首先,如果你只需要知道blob的数量, ,那么 bwboundaries 是一个过度的。相反,您可以使用 bwconncomp ,它只会查找和标记blob 。

First of all, if you only need to know the number of blobs, and you do not need their boundary pixels, then bwboundaries is an overkill. Instead, you can use bwconncomp, which will just find and label the blobs.

其次,这里最大的问题是你要反转掩码。所以你实际上是在后台找到连接的组件,而不是在前台。你计算书之间的空格,而不是书本身。所以不要做 BW2 =〜BW2;

Second, it seems that the biggest problem here is that you are inverting the mask. So you are actually trying to find connected components in the background, instead of in the foreground. You are counting empty spaces between the books, instead of the books themselves. So don't do BW2=~BW2;

最后,图像中可能有blob造成的噪音,而不是书。因此,您需要或者拒绝太小的斑点,或者在手前对掩模进行一些预处理。例如,你可以尝试形态开放以摆脱小的孤立的前景像素块。

Finally, there are may be blobs in the image that are caused by noise, and not books. So you need to either reject blobs that are too small, or do some preprocessing on the mask before hand. For example, you can try morphological opening to get rid of small isolated clumps of foreground pixels.

还请查看 regionprops 函数。您可能会发现它很有用。

P.S. Also please take a look at the regionprops function. You may find it useful.

这篇关于通过MatLab计算Blob的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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