图像的反卷积卷积、图像

2023-09-11 03:45:07 作者:从心

我有源和结果的图像。我知道,有些卷积矩阵已用于源得到的结果。可这卷积矩阵计算?或者至少不准确的,但非常相似。

I have source and result image. I know, that some convolution matrix has been used on source to get result. Can this convolution matrix be computed ? Or at least not exact one, but very similar.

推荐答案

在原则上,是的。只是使用 FFT 的两个图像转换为频率空间和由该源图像的分割的结果图像的FFT。然后应用逆FFT,以获得卷积核的近似。

In principle, yes. Just convert both images to frequency space using an FFT and divide the FFT of the result image by that of the source image. Then apply the inverse FFT to get an approximation of the convolution kernel.

要明白为什么这个作品,注意对应的频域的乘法的卷积在空间域,所以去卷积同样对应师在频域。在普通的反卷积,人们将划分卷积图像的FFT由该内核恢复原始图像。然而,由于卷积(像乘法)是可交换的操作中,内核和角色的源可以任意地交换:由内核卷积源是完全一样由源卷积内核

To see why this works, note that convolution in the spatial domain corresponds to multiplication in the frequency domain, and so deconvolution similarly corresponds to division in the frequency domain. In ordinary deconvolution, one would divide the FFT of the convolved image by that of the kernel to recover the original image. However, since convolution (like multiplication) is a commutative operation, the roles of the kernel and the source can be arbitrarily exchanged: convolving the source by the kernel is exactly the same as convolving the kernel by the source.

作为其他的答案注意,但是,这是不可能产生内核的精确重建,出于同样的理由作为普通卷积通常将不完全重建原始图像:舍入和削波将噪声引入的过程中,并有可能为卷积完全消灭某些频率(通过将它们与零相乘),在这种情况下,这些频率不能被重构。

As the other answers note, however, this is unlikely to yield an exact reconstruction of your kernel, for the same reasons as ordinary deconvolution generally won't exactly reconstruct the original image: rounding and clipping will introduce noise into the process, and it's possible for the convolution to completely wipe out some frequencies (by multiplying them with zero), in which case those frequencies cannot be reconstructed.

这是说,如果你原来的内核是有限的大小(支持)的,重建的内核通常应该有大约起源一个尖峰,接近原来的内核,由低层次的噪音所包围。即使你不知道原来内核的确切大小,应该不会太难提取此峰值,并丢弃重建的其余部分。

That said, if your original kernel was of limited size (support), the reconstructed kernel should typically have a single sharp peak around the origin, approximating the original kernel, surrounded by low-level noise. Even if you don't know the exact size of the original kernel, it shouldn't be too hard to extract this peak and discard the rest of the reconstruction.

这里是莱娜图测试图片的灰度,缩减到256倍; 256像素,卷积了5倍; 5内核在GIMP:

Here's the Lenna test image in grayscale, scaled down to 256×256 pixels and convolved with a 5×5 kernel in GIMP:

* →

∗ →

我会用Python和numpy的/ SciPy的用于反卷积:

I'll use Python with numpy/scipy for the deconvolution:

from scipy import misc
from numpy import fft

orig = misc.imread('lena256.png')
blur = misc.imread('lena256blur.png')
orig_f = fft.rfft2(orig)
blur_f = fft.rfft2(blur)

kernel_f = blur_f / orig_f         # do the deconvolution
kernel = fft.irfft2(kernel_f)      # inverse Fourier transform
kernel = fft.fftshift(kernel)      # shift origin to center of image
kernel /= kernel.max()             # normalize gray levels
misc.imsave('kernel.png', kernel)  # save reconstructed kernel

将所得的256倍; 256图像的内核,和7倍的变焦;绕其中心7像素区域,如下所示:

The resulting 256×256 image of the kernel, and a zoom of the 7×7 pixel region around its center, are shown below:

重建与原内核相比,你可以看到,他们看起来类似pretty的;的确,施加截止之间的任何地方0.5和0.68到重建会恢复原来的内核。围绕在重建高峰期的微弱的涟漪噪声由于四舍五入的原因和边缘效应。

Comparing the reconstruction with the original kernel, you can see that they look pretty similar; indeed, applying a cutoff anywhere between 0.5 and 0.68 to the reconstruction will recover the original kernel. The faint ripples surrounding the peak in the reconstruction are noise due to rounding and edge effects.

我不完全知道是什么导致出现在重建(虽然我敢肯定,有人用这些东西可以告诉你更多的经验)十字形神器,但是从我的头顶,我的猜测是,它有是与图像边缘。当余卷积在GIMP原始图像时,我告诉它通过扩展图像(实质上是复制的最外的像素)来处理的边缘,而在FFT卷积假定图像边缘环绕。这很可能引入沿x轴和y轴杂散相关的重建。

I'm not entirely sure what's causing the cross-shaped artifact that appears in the reconstruction (although I'm sure someone with more experience with these things could tell you), but off the top of my head, my guess would be that it has something to do with the image edges. When I convolved the original image in GIMP, I told it to handle edges by extending the image (essentially copying the outermost pixels), whereas the FFT deconvolution assumes that the image edges wrap around. This may well introduce spurious correlations along the x and y axes in the reconstruction.