algorithm - 无法在 MATLAB 中分隔标记

标签 algorithm matlab image-processing

我的图像上到处都是白点。现在,我想根据某些坐标和检查在每个点上放置一个标记。现在我的问题是,我不想在占用超过一个像素的一个特定“ Blob ”白点上聚集太多标记。我的解决方法是检查我以前的标记位置和我当前的标记位置是否在附近。然而,这会导致许多独立的白色 Blob 由于距离太近而被遗漏,即使它不一定只是一个 Blob 。

这是我当前的代码:

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

关于如何解决这个问题有什么想法吗?

最佳答案

您可以使用 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 的每个像素上放置一个标记。

关于algorithm - 无法在 MATLAB 中分隔标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223291/

相关文章:

algorithm - 函数的渐近增长

r - R 和 MATLAB 中不同的 SVD 结果

python - re.findall为负数,我的代码仅适用于正数

android - 在 Android 中模糊图像的一部分

c# - 如何找到直线斜率变化的点?

python:从二维网格中无替换地采样

java - 在矩形流中进行快速点搜索

matlab - 矩阵内的操作避免循环

matlab - 使用 cellfun 进行条件元素替换

c# - 移动端角点检测算法