如何使用 PSF 内核(图像格式)从清晰图像创建合成模糊图像

How to create synthetic blurred image from sharp image using PSF kernel (in image format)

根据@Fix 的建议更新我应该将 BGR 转换为 RGB,但输出仍然与论文的输出不同。

(小提示:这个 post 已经在 https://dsp.stackexchange.com/posts/60670 上 post 但是因为我需要快速帮助所以我想我在这里重新 post 了,希望这不会'不违反任何政策)

我尝试使用 PSF 内核(png 格式)从 ground-truth 图像创建合成模糊图像,一些论文只提到我需要对其进行卷积操作,但似乎我需要更多比起那个来说。 我做了什么

import matplotlib.pyplot as plt
import cv2 as cv
import scipy
from scipy import ndimage
import matplotlib.image as mpimg
import numpy as np

img = cv.imread('../dataset/text_01.png')
norm_image = cv.normalize(img, None, alpha=-0.1, beta=1.8, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)

f = cv.imread('../matlab/uniform_kernel/kernel_01.png')
norm_f = cv.normalize(f, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)

result = ndimage.convolve(norm_image, norm_f, mode='nearest')

result = np.clip(result, 0, 1)

imgplot = plt.imshow(result)
plt.show()

这只给我一张 white-entire 图片。 我在这里尝试将 beta 降低到更低的数字 norm_f = cv.normalize(f, None, alpha=0, beta=0.03, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F) 并且图像出现了,但它的颜色非常不同。

我知道如何做到这一点的论文和数据集(具有 ground-truth 的图像和 PNG 格式的 PSF 内核)是 here

他们是这样说的:

We create the synthetic saturated images in a way similar to [3, 10]. Specifically, we first stretch the intensity range of the latent image from [0,1] to [−0.1,1.8], and convolve the blur kernels with the images. We then clip the blurred images into the range of [0,1]. The same process is adopted for generating non-uniform blurred images.

这是我从我的来源获得的一些图片。

这是 ground-truth 图片:

这是PNG格式文件中的PSF内核:

这是他们的输出(合成图像):

请帮帮我,解决方案并不重要,即使它是一个软件,另一种语言,另一种工具。我只关心最终我从具有良好性能的 PSF 内核的原始(清晰)图像合成模糊图像(我在 Matlab 上尝试过但遇到了类似的问题,我使用了 imfilter,Matlab 的另一个问题是它们很慢)。

(请不要判断只关心过程的输出,我没有使用 deconvol 方法去模糊模糊回到原始图像,所以我想有足够的数据集(原始和模糊)对来测试我的 hypothesis/method)

谢谢。

OpenCV 以 BGR 格式读取/写入图像,以 RGB 格式读取/写入 Matplotlib。所以如果你想显示正确的颜色,你应该先把它转换成 RGB :

result_rgb = cv.cvtColor(result, cv.COLOR_BGR2RGB)
imgplot = plt.imshow(result)
plt.show()

编辑:您可以分别对每个通道进行卷积并像这样标准化您的卷积图像:

f = cv.cvtColor(f, cv.COLOR_BGR2GRAY)  
norm_image = img / 255.0
norm_f = f / 255.0  
result0 = ndimage.convolve(norm_image[:,:,0], norm_f)/(np.sum(norm_f))
result1 = ndimage.convolve(norm_image[:,:,1], norm_f)/(np.sum(norm_f))
result2 = ndimage.convolve(norm_image[:,:,2], norm_f)/(np.sum(norm_f))
result = np.stack((result0, result1, result2), axis=2).astype(np.float32)

那么你应该得到正确的颜色。尽管这对图像和内核都使用了 0.0 到 1.0 之间的归一化(不同于论文建议的图像在 -0.1 到 1.8 之间)。