【发布时间】:2015-02-09 10:49:00
【问题描述】:
我有一个包含一些点和许多零元素的像素矩阵。从那些非零点中,我想丢弃那些在矩阵 N 范围内具有更强点的点。范围是像素之间的欧几里得距离。
input = [0.0 0.0 0.0 0.9 0.0 0.0
0.0 0.0 0.2 0.0 0.0 0.5
0.0 0.0 0.7 0.0 0.0 0.0
0.0 0.4 0.1 0.0 0.0 0.0];
output = [0.0 0.0 0.0 0.9 0.0 0.0 % 0.7 is the largest number in range
0.0 0.0 0.0 0.0 0.0 0.5 % 0.2 got removed; was next to 0.9 and 0.7
0.0 0.0 0.7 0.0 0.0 0.0 % 0.7 is the largest number in range
0.0 0.0 0.0 0.0 0.0 0.0]; % 0.1 and 0.4 both got removed; were next to 0.7
更新:这是我目前为止的想法。它遍历所有非零像素并将当前像素与邻域中的最大像素进行比较。但是,该邻域包含许多像素。我需要以某种方式选择圆形区域,而不是通过索引偏移选择区域。此外,如果有更短的方法,我将不胜感激,也许用内置的 Matlab 函数替换循环,如 conv2 或 imfilter。
% Discard points near stronger points
points = find(Image > 0);
radius = args.Results.min_dist;
for i = 1:size(points)
[index_y, index_x] = ind2sub(size(Image), points(i));
% Find neighborhood
from_x = max(index_x-radius, 1);
from_y = max(index_y-radius, 1);
to_x = min(index_x+radius, size(Image, 2));
to_y = min(index_y+radius, size(Image, 1));
neighbors = Image(from_y:to_y, from_x:to_x);
% Discard if there is a stronger neighbor
largest = max(max(neighbors));
if Image(index_y, index_x) < largest
Image(index_y, index_x) = 0;
end
end
【问题讨论】:
-
你如何定义“强点”?
-
@Divakar 更重要的是,我只是指像素矩阵中较大的值。
-
嗯,这就是我在这里定义“强”和“弱”的意思。我想这里必须有一些加权标准。
-
你有图片处理工具箱吗?
-
@mehmet 如果在 N 的欧几里德距离内只有较小的像素(或根本没有像素),我想将像素保持在 0.3 以下。
标签: matlab image-processing matrix distance vectorization