我假设您的图像中有 1 个像素宽度的线条比其周围环境更亮或更暗,您希望找到它们并将它们从图像中移除,并用本地邻域的平均值替换移除的像素。
我为此开发了一种算法,它适用于我的示例数据(因为您没有提供任何数据)。它有两个部分:
线路识别
我想不出一种简单但有效的过滤器来检测线(它们是连接的,因此可能需要查看相关性)。所以我使用了一个简单的单像素检测过滤器:
-1 -1 -1
-1 8 -1
-1 -1 -1
然后是一些合适的阈值。
将掩码外部的数据外推到掩码
一个非常优雅的解决方案(仅使用卷积)是将掩码之外的数据与高斯进行卷积,然后采用负掩码并将其与相同的高斯进行卷积,然后按像素划分。蒙版内的结果是所需的模糊。
它在数学上是什么:数据的加权平均。
这是我的幻像数据:

这是线条的识别

最终结果表明失真被抑制了十倍:

最后是我的代码(在 Matlab 中):
%% create phantom data with lines (1pixel wide bands)
[x, y] = ndgrid(1:100, 1:100);
original = 3 * x - 2 * y + 100 * sin(x / 2) + 120 * cos(y / 3); % funny shapes
bw = original > mean(original(:)); % black and white
distortion = bwmorph(bw,'remove'); % some lines
data = original + max(original(:)) * distortion; % phantom
% show
figure();
subplot(1,3,1); imagesc(original); axis image; colormap(hot); title('original');
subplot(1,3,2); imagesc(distortion); axis image; title('distortion');
subplot(1,3,3); imagesc(data); axis image; title('image');
%% line detection
% filter by single pixel filter
pixel_filtered = filter2([-1,-1,-1;-1,8,-1;-1,-1,-1], data);
% create mask by simple thresholding
mask = pixel_filtered > 0.2 * max(pixel_filtered(:));
% show
figure();
subplot(1,2,1); imagesc(pixel_filtered); axis image; colormap(hot); title('filtered');
subplot(1,2,2); imagesc(mask); axis image; title('mask');
%% line removal and interpolation
% smoothing kernel: gaussian
smooth_kernel = fspecial('gaussian', [3, 3], 1);
smooth_kernel = smooth_kernel ./ sum(smooth_kernel(:)); % normalize to one
% smooth image outside mask and divide by smoothed negative mask
smoothed = filter2(smooth_kernel, data .* ~mask) ./ filter2(smooth_kernel, ~mask);
% withing mask set data to smoothed
reconstruction = data .* ~mask + smoothed .* mask;
% show
figure();
subplot(1,3,1); imagesc(reconstruction); axis image; colormap(hot); title('reconstruction');
subplot(1,3,2); imagesc(original); axis image; title('original');
subplot(1,3,3); imagesc(reconstruction - original); axis image; title('difference');