cra*_*ict 9 matlab interpolation image-processing computer-vision

任何人都可以帮助我用相邻非零像素的值填充这些黑洞.谢谢
一个很好的方法是解决线性热方程.你所做的是修复好区域中像素的"温度"(强度),让热量流入坏像素.一个可通过的,但有点慢,是这样做是重复平均图像然后将好像素设置回原始值newImage(~badPixels) = myData(~badPixels);.
我执行以下步骤:
您可以重复平均,直到图像停止变化,并且您可以使用较小的平均内核以获得更高的精度 - 但这会产生良好的结果:

代码如下:
numIterations = 30;
avgPrecisionSize = 16; % smaller is better, but takes longer
% Read in the image grayscale:
originalImage = double(rgb2gray(imread('c:\temp\testimage.jpg')));
% get the bad pixels where = 0 and dilate to make sure they get everything:
badPixels = (originalImage == 0);
badPixels = imdilate(badPixels, ones(12));
%# Create a big gaussian and an averaging kernel to use:
G = fspecial('gaussian',[1 1]*100,50);
H = fspecial('average', [1,1]*avgPrecisionSize);
%# User a big filter to get started:
newImage = imfilter(originalImage,G,'same');
newImage(~badPixels) = originalImage(~badPixels);
% Now average to
for count = 1:numIterations
newImage = imfilter(newImage, H, 'same');
newImage(~badPixels) = originalImage(~badPixels);
end
%% Plot the results
figure(123);
clf;
% Display the mask:
subplot(1,2,1);
imagesc(badPixels);
axis image
title('Region Of the Bad Pixels');
% Display the result:
subplot(1,2,2);
imagesc(newImage);
axis image
set(gca,'clim', [0 255])
title('Infilled Image');
colormap gray
Run Code Online (Sandbox Code Playgroud)
但您可以roifill从图像处理工具箱中获得类似的解决方案,如下所示:
newImage2 = roifill(originalImage, badPixels);
figure(44);
clf;
imagesc(newImage2);
colormap gray
Run Code Online (Sandbox Code Playgroud)
注意我使用的是之前定义的相同badPixels.