algorithm - Detect black dots from color background -


my short question

how detect black dots in following images? (i paste 1 test image make question compact. more images can found →here←).

enter image description here

my long question

as shown above, background color blue, , dots color "black". if pick 1 black pixel , measure color in rgb, value can enter image description here (0, 44, 65) or enter image description here (14, 69, 89).... therefore, cannot set range tell pixel part of black dot or background.

i test 10 images of different colors, hope can find method detect black dots more complicated background may made of 3 or more colors, long human eyes can identify black dots easily. extremely small or blur dots can omitted.

previous work

last month, have asked a similar question @ stackoverflow, have not got perfect solution, excellent answers though. find more details work if interested.

here methods have tried:

  1. converting grayscale or brightness of image. difficulty can not find adaptive threshold binarization. obviously, turning color image grayscale or using brightness (hsv) lose useful information. otsu algorithm calculates adaptive threshold can not work either.

  2. calculating rgb histogram. in last question, natan's method estimate black color histogram. time-saving, adaptive threshold problem.

  3. clustering. have tried k-means clustering , found quite effective background has 1 color. shortage (see own answer) need set number of clustering center in advance don't know how background be. what's more, slow! application real time capturing on iphone , can process 7~8 frames per second using k-means (20 fps think).

summary

i think not similar colors adjacent pixels should "clustered" or "merged" in order extract black dots. please guide me proper way solve problem. advice or algorithm appreciated. there no free lunch hope better trade-off between cost , accuracy.

i able pretty nice first pass results converting hsv color space rgb2hsv, using image processing toolbox functions imopen , imregionalmin on 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 resulting images (for image in question , 1 chosen link):

enter image description here

enter image description here

you can see few false positives , missed dots, dots labeled multiple points, few refinements (such modifying structure element used in opening step) clean these some.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -