2944014083-zhiyu

背景

        今天有个小伙伴问我图片小波变换的后再重构的矩阵怎么显示出来时一片白,刚开始我以为时重构的参数出了问题,调试了代码发现,是灰度矩阵转为图片的代码不对,数据类型也没变换

核心代码

方法1

from PIL import Image

new_img=Image.fromarray(dataArray)
new_img.show()

方法2

import matplotlib.pyplot as plt

plt.imshow(dataArray,cmap=\'gray\')

       

import pywt
import numpy as np
from cv2 import cv2
from PIL import Image
import matplotlib.pyplot as plt

img = cv2.imread("lenags15.bmp", 0)
w = \'sym4\'  # 定义小波基的类型
l = 3  # 变换层次为3
coeffs = pywt.wavedec2(data=img, wavelet=w, level=l)
threshold = 0.04  # 设置滤波阈值
denoised_img = pywt.waverec2(coeffs, \'sym4\' ,mode="sym")

denoised_img = denoised_img.astype(np.uint8)

\'\'\'方法1\'\'\'
new_img=Image.fromarray(denoised_img)
new_img.show()
\'\'\'方法1\'\'\'

\'\'\'方法2\'\'\'
# plt.imshow(denoised_img,cmap=\'gray\')
\'\'\'方法2\'\'\'

分类:

技术点:

相关文章:

  • 2021-12-05
猜你喜欢
  • 2021-12-05
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-05
相关资源
相似解决方案