从颜色背景检测黑点 [英] Detect black dots from color background

查看:271
本文介绍了从颜色背景检测黑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的简短问题



如何检测以下图像中的黑点? (我只粘贴一个测试图片,使问题看起来更紧凑。可以找到更多图片也无法工作。


  • 计算RGB直方图。在我最后一个问题中, 的方法是通过直方图估计黑色。这是省时的,但自适应阈值也是一个问题。


  • 群集。我试过 k-means聚类,发现它对于只有一种颜色。缺点(见我自己的回答)是我需要提前设置聚类中心的数量,但我不知道背景将如何。此外,太!我的应用程序是在iPhone上的实时捕获,现在它可以处理7〜8帧每秒使用k-means(20 FPS是好的我想)。




  • 总结



    我认为不仅相似的颜色,而且相邻的像素应该是聚集或合并,以提取黑点。请指导我一个正确的方法来解决我的问题。任何建议或算法将不胜感激。没有免费午餐,但我希望在成本和准确性之间有一个更好的折衷。

    解决方案

    通过 rgb2hsv转换为HSV颜色空间,获得良好的第一遍结果 ,然后使用图像处理工具箱函数 imopen imregionalmin

      rgb = imread('6abIc.jpg'); 
    hsv = rgb2hsv(rgb);
    openimg = imopen(hsv(:,:,3),strel('disk',11));
    mask = imregionalmin(openimg);
    imshow(rgb);
    hold on;
    [r,c] = find(mask);
    plot(c,r,'r。');

    生成的图片(问题中的图片和从链接中选择的图片) p>





    您可以看到一些假阳性和漏点,以及一些标记有多个点的点,但有些细化(例如修改开始步骤中使用的结构元素)可能会清除一些。 / p>

    My short question

    How to detect the black dots in the following images? (I paste only one test image to make the question look compact. More images can be found →here←).

    My long question

    As shown above, the background color is roughly blue, and the dots color is "black". If pick one black pixel and measure its color in RGB, the value can be (0, 44, 65) or (14, 69, 89).... Therefore, we cannot set a range to tell the pixel is part of the black dot or the background.

    I test 10 images of different colors, but I hope I can find a method to detect the black dots from more complicated background which may be made up of three or more colors, as long as human eyes can identify the black dots easily. Some extremely small or blur dots can be omitted.

    Previous work

    Last month, I have asked a similar question at stackoverflow, but have not got a perfect solution, some excellent answers though. Find more details about my work if you are interested.

    Here are the methods I have tried:

    1. Converting to grayscale or the brightness of image. The difficulty is that I can not find an adaptive threshold to do binarization. Obviously, turning a color image to grayscale or using the brightness (HSV) will lose much useful information. Otsu algorithm which calculates adaptive threshold can not work either.

    2. Calculating RGB histogram. In my last question, natan's method is to estimate the black color by histogram. It is time-saving, but the adaptive threshold is also a problem.

    3. Clustering. I have tried k-means clustering and found it quite effective for the background that only has one color. The shortage (see my own answer) is I need to set the number of clustering center in advance but I don't know how the background will be. What's more, it is too slow! My application is for real time capturing on iPhone and now it can process 7~8 frames per second using k-means (20 FPS is good I think).

    Summary

    I think not only similar colors but also adjacent pixels should be "clustered" or "merged" in order to extract the black dots. Please guide me a proper way to solve my problem. Any advice or algorithm will be appreciated. There is no free lunch but I hope a better trade-off between cost and accuracy.

    解决方案

    I was able to get some pretty nice first pass results by converting to HSV color space with rgb2hsv, then using the Image Processing Toolbox functions imopen and imregionalmin on the value channel:

    rgb = imread('6abIc.jpg');
    hsv = rgb2hsv(rgb);
    openimg = imopen(hsv(:, :, 3), strel('disk', 11));
    mask = imregionalmin(openimg);
    imshow(rgb);
    hold on;
    [r, c] = find(mask);
    plot(c, r, 'r.');
    

    And the resulting images (for the image in the question and one chosen from your link):

    You can see a few false positives and missed dots, as well as some dots that are labeled with multiple points, but a few refinements (such as modifying the structure element used in the opening step) could clean these up some.

    这篇关于从颜色背景检测黑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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