本文介绍了n维numpy.gradient的逆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

numpy或scipy是否包含一个与n维梯度" fn相反的函数?

Does numpy or scipy contain a function which is an inverse of the n-dimensional "gradient" fn?

例如如果图像"包含2D矩阵,则我想要一个功能如下的inv_gradient函数:

E.g. if "image" contains a 2D matrix, then i want a function inv_gradient that behaves as follows:

(gx, gy) = numpy.gradient(image)
constant_vector_0 = image[0,:] - inv_gradient(gx, gy)[0,:]
constant_vector_1 = image[:,0] - inv_gradient(gx, gy)[:,0]
image == inv_gradient(gx, gy) + tile(constant_vector_0,(shape(image)[0],1)) + transpose(tile(constant_vector_1,(shape(image)[1],1)))

推荐答案

您所描述的基本上是一个逆滤波器.这些存在,但有限制.

What you are describing is basically an inverse filter. These exist, but are limited.

了解这一点的一种方法是通过卷积定理,并将梯度视为卷积的特定内核,在这种情况下,类似于一维中的(-1,0,1).然后的问题是,内核的傅立叶变换(FT)将为零,并且当内核的FT与信号的FT相乘时,内核的FT中的零将擦除该部分中原始数据中的所有数据.频谱(当将噪声添加到图像时,这会带来更多问题).专门针对渐变,f = 0波段中的功率为0,这就是人们在评论中所指的,但其他信息也丢失了.

One way to understand this is via the convolution theorem, and to think of the gradient as a particular kernel for a convolution, in this case something like (-1, 0, 1) in 1D. The issue then, is that the Fourier Transform (FT) of the kernel will have zeroes, and that when the FTs of the kernel and signal are multiplied, the zeroes in the kernel's FT wipes out any data from the original data in this part of the spectrum (and this gets more problematic when noise is added to the image). Specifically for the gradient, there is 0 power in the f=0 band, and this is what people are referring to in the comments, but other information is lost as well.

尽管如此,您仍然可以从逆滤波器中获得很多收益,也许还有您需要的东西.这是相当具体的情况.

Still, though, you can get a lot out of an inverse filter, and maybe what you need. It's fairly case specific.

这是关于此问题的非常基本且快速的描述,以及示例(尽管不是用于渐变)

Here's a very basic and quick description of the issue, and an example (though not for gradients).

这篇关于n维numpy.gradient的逆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:27