Detect black dots from color background

前端 未结 3 846
攒了一身酷
攒了一身酷 2021-02-01 23:04

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←

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 23:10

    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):

    enter image description here

    enter image description here

    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.

提交回复
热议问题