Counting number of Blobs via MatLab

て烟熏妆下的殇ゞ 提交于 2019-12-08 02:51:16

问题


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

This method is adopted from http://www.instructables.com/id/Image-Processing-and-Counting-using-MATLAB/step5/Find-the-Boundaries-of-the-Objects/

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?

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.


回答1:


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.

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;

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.

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




回答2:


Here is one thing you can try, I expect this to work for at least the second failed example:

Rather than only analysing the entire image at once, consider cutting it up and then analysing it.

Suppose you cut it into 5 columns (assuming the books are always lying down) then you can perform the analysis 5 times. Afterwards you can take the median for example, and hopefully get a more accurate result.



来源:https://stackoverflow.com/questions/19586464/counting-number-of-blobs-via-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!