Image Processing Issue: Fill NaNs in image, which mostly consists of NaNs

大兔子大兔子 提交于 2019-12-04 17:25:16

You might try the TriScatteredInterp function. It works well in my simple test:

% create an image with holes
x = im2double(imread('rice.png'));
x(1:4:end, 1:4:end) = nan;
x(rand(size(x))<.1) = nan;
figure; imshow(x);

% setup the grid to interp from
[m n c] = size(x);
[N M] = meshgrid(1:m, 1:n);
Ni = N;
Mi = M;

Mi(~isnan(x)) = [];
Ni(~isnan(x)) = [];

N(isnan(x)) = [];
M(isnan(x)) = [];
Z = x(~isnan(x));

% do the interp
F = TriScatteredInterp(M', N', Z);
Zi = F(Mi, Ni);

xi = x;
xi(sub2ind(size(x),Mi, Ni)) = Zi;
figure; imshow(xi);

I had similar situation and simple imdilate worked for me. TriScatteredInterp is quite slow. The post is quite old but maybe following code helpful to somebody:

imgDepth = load('depthImage.mat') % Or imread('depthImage.png')
imgDepth(isnan(imgDepth)) = 0
radius = 10 % Change as per your data
se = strel('disk',radius) % Try different structuring elements as per your need
imgDilated = imdilate(imgDepth,se);
figure,imshow(imgDilated,[]),colormap(jet)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!