mnzhang01 / MD_Net

Self-supervised multi-scale neural network for blind deblurring
2 stars 0 forks source link

合成数据集 #2

Open changjh23 opened 3 months ago

changjh23 commented 3 months ago

您好!

打扰您了!

我有一个问题想请教一下,您文章中提及使用 CelebA dataset 中的清晰图像,与《Discriminative non-blind deblurring》所生成的模糊卷积,得到模糊数据集face images

想请问一下是如何进行卷积的,是不是有什么需要注意的事项?我自己写的代码得到的模糊图像,去模糊效果很差,我的方法肯定有问题,想请教一下您如何改进。

我的方法类似于这样

import numpy as np
from matplotlib import pyplot as plt

def apply_blur(image, kernel):
    # 分离图像通道
    image_channels = cv2.split(image)

    # 归一化模糊核
    kernel = kernel / np.sum(kernel)

    # 对每个通道应用卷积
    blurred_channels = [cv2.filter2D(channel, -1, kernel) for channel in image_channels]

    # 合并通道
    blurred_image = cv2.merge(blurred_channels)

    return blurred_image

# 读取彩色图像
image_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\gt\img1.png'
image = np.float32(cv2.imread(image_path)) / 255.0

# 读取模糊核(单通道的PNG文件)
kernel_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\gt\kernel_05.png'
kernel = np.float32(cv2.imread(kernel_path, cv2.IMREAD_GRAYSCALE))

# 应用模糊
blurred_image = apply_blur(image, kernel)

# 显示原始图像和模糊图像
plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.subplot(1, 2, 2)
plt.title('Blurred Image')
plt.imshow(cv2.cvtColor(blurred_image, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.show()

# 保存模糊图像
output_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\blur\im3_kernel_01.png'  # 替换为你想保存图像的路径
cv2.imwrite(output_path, (blurred_image * 255).astype(np.uint8))
print(f"Blurred image saved to {output_path}")

十分感谢!

mnzhang01 commented 3 months ago

您加一下我微信吧 15947417346 ---- 回复的原邮件 ---- @.>发送日期2024年06月04日 20:33 @.> @.>主题[mnzhang01/MD_Net] 合成数据集 (Issue #2) 您好! 打扰您了! 我有一个问题想请教一下,您文章中提及使用 CelebA dataset 中的清晰图像,与《Discriminative non-blind deblurring》所生成的模糊卷积,得到模糊数据集face images。 想请问一下是如何进行卷积的,是不是有什么需要注意的事项?我自己写的代码得到的模糊图像,去模糊效果很差,我的方法肯定有问题,想请教一下您如何改进。 我的方法类似于这样 import numpy as np from matplotlib import pyplot as plt def apply_blur(image, kernel): # 分离图像通道 image_channels = cv2.split(image) # 归一化模糊核 kernel = kernel / np.sum(kernel) # 对每个通道应用卷积 blurred_channels = [cv2.filter2D(channel, -1, kernel) for channel in image_channels] # 合并通道 blurred_image = cv2.merge(blurred_channels) return blurred_image # 读取彩色图像 image_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\gt\img1.png' image = np.float32(cv2.imread(image_path)) / 255.0 # 读取模糊核(单通道的PNG文件) kernel_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\gt\kernel_05.png' kernel = np.float32(cv2.imread(kernel_path, cv2.IMREAD_GRAYSCALE)) # 应用模糊 blurred_image = apply_blur(image, kernel) # 显示原始图像和模糊图像 plt.figure(figsize=(10, 5)) plt.subplot(1, 2, 1) plt.title('Original Image') plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) plt.axis('off') plt.subplot(1, 2, 2) plt.title('Blurred Image') plt.imshow(cv2.cvtColor(blurred_image, cv2.COLOR_BGR2RGB)) plt.axis('off') plt.show() # 保存模糊图像 output_path = r'E:\DLCode_cjh\Deblur\Non-blind-deblur\Datasets\BSDS300-images\BSD3\blur\im3_kernel_01.png' # 替换为你想保存图像的路径 cv2.imwrite(output_path, (blurred_image 255).astype(np.uint8)) print(f"Blurred image saved to {output_path}") 十分感谢! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: **@.***>