图像处理问题:在图像中填充NaN,其主要由NaN组成 [英] Image Processing Issue: Fill NaNs in image, which mostly consists of NaNs

查看:296
本文介绍了图像处理问题:在图像中填充NaN,其主要由NaN组成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集/图像 DD 就像这张图片中的那个:

I have a dataset / image DD like the one in this image:

(顺便说一下:有没有办法在这里上传小数据集,这样你就可以使用我使用的相同数据,而不必将它们放在代码中?)

(by the way: is there a way of uploading small data sets here, so that you can actually work with the same data I use, without having to put them in the code?)

图像中的彩色像素表示高度/深度范围从0到大约400 米。蓝色像素 NaN

Colored pixels in the image represent height/depth ranging from 0 to about 400  meters. Blue pixels are NaN.

现在我需要做的是在显示的对象中插入像素值,但没有插入整个图像。

Now what I need to do is to interpolate the pixel values WITHIN the displayed object, but without interpolating the whole image.

我尝试使用文件交换中的函数 inpaint_nans ,这对我一次又一次地帮助了我做得不错:

I tried using the function inpaint_nans from the file-exchange, which has helped me quite often and again, it did a decent job:

imagesc(inpaint_nans(DD,4))

然而,对于大约3000x3000像素的大型图像,运行时间相当长(我有一些像素!)并不完全正确,我正在寻找。图像处理工具箱中是否有一个函数可以将插值限制在我对象的现有边界而不考虑周围的NaN?

However, the runtime is fairly long for large images of ~3000x3000 pixels (and I have a few of them!) and it is not exactly, what I am looking for. Is there a function within the image processing toolbox maybe, that restricts the interpolation to the existing boundaries of my object without taking into account the surrounding NaNs?

我也像这样使用 interp2

[xi,yi] = meshgrid(1:size(DD,2),1:size(DD,1));
zi = interp2(xi,yi,DD,xi,yi,'method');
imagesc(zi)

我试过线性方法,c $ c>,最近立方。他们没有完成这项工作。 最近的没有做任何事情,而其余部分删除了越来越多的好像素,并用 NaN 替换它们。任何帮助或建议将不胜感激!

where I tried linear, nearest and cubicfor method. Non of them did the job. nearestdid not do anything, while the rest removed more and more "good" pixels and substituted them by NaNs. Any help or suggestions would be appreciated!

编辑:处理:

我在另一个程序中运行模拟,这是基于三角形网格。对于网格的每个节点(X,Y),水深被写入ascii文件。在流的中心,2个三角形适合一个像素(90×90米),例如,我得到像素角的水深值,而不是像素本身。在周围,模拟以更大的间距工作(从洪泛区内的常规NaN值可以看出)。这里,2个三角形构成180x180米(4个像素)的矩形。因为我只获得三角形节点的值,所以计算的水深值被分配给每秒,而不是每个像素。
现在我想,最简单的方法是在像素之间进行插值。另一个有效(可能更好)的解决方案是将节点值(深度)分配给周围的2/4像素:

I ran a simulation in a different program, that was based on triangular meshs. For each node of the mesh (X,Y), the water depth is written to an ascii file. In the center of the stream, the 2 triangles fit in one pixel (90x90meters), e.g., I get water depth values for the corners of a pixel, not the pixel itself. At surrounding, the simulation works with a larger spacing (as is evident from the regular NaN values within the floodplain). Here, 2 triangles make up a rectangle of 180x180 meters (4 pixels). Because I only get values for the nodes of the triangles again, the calculated water depth value is assigned to every second, not every pixel. Now I thought, the easiest method would be to interpolate between the pixels. Another valid (maybe better) solution, would be to assign the node value (depth) to the surrounding 2 / 4 pixels:

推荐答案

您可以尝试 TriScatteredInterp 功能。它在我的简单测试中效果很好:

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);

这篇关于图像处理问题:在图像中填充NaN,其主要由NaN组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆