首页 文章

无法在MATLAB中分隔标记

提问于
浏览
1

我有一张白色斑点的图像 . 现在,我想根据某些坐标和检查在每个点上放置一个标记 . 现在我的问题是,我不想在占据超过一个像素的白色斑点的一个特定“斑点”上聚集太多标记 . 我的工作是检查我之前的标记位置和我的当前是否在附近 . 然而,这导致很多独立的白色斑点由于非常接近而被遗漏,即使它不一定只是一个斑点 .

这是我目前的代码:

a = find(overlap == 1); %overlap is a 1040 by 1392 binary matrix
prev_coord = [1 1];

for i=1:size(a)
    c = mod(a(i), 1040);
    r = floor(a(i)/1040);
    X = [prev_coord; r c];
    if(pdist(X, 'euclidean') > prox)      
       if(img(r, c) > 1)
           gray = insertMarker(gray, [r c], 'x', 'color', 'red', 'size', 15); 
       else
           gray = insertMarker(gray, [r c], 'x', 'color', 'white', 'size', 15);      
       end
    end
    prev_coord = [r c];
end

prox 等于50这样的非常小的数字时,我的图像如下所示:
enter image description here

但是,当 prox 是120这样的大数字时,它看起来像这样:
enter image description here

关于如何解决这个问题的任何想法?

1 回答

  • 2

    你可以使用morphological operations来做到这一点:

    A = round(overlap./max(overlap(:))) % turn original image into binary image.
    A = imfill(A,'holes'); % fill holes in blobs
    A = bwmorph(A,'shrink',Inf) % reduce each blob to a single point
    

    然后你可以在 A==1 的每个像素上放置一个标记 .

相关问题