Mahotas – 从变换后的 Daubechies 小波图像重建图像
在本文中,我们将了解如何从 mahotas 中的 daubechies 小波变换图像重建图像。一般来说,对于给定的支撑宽度 2A,Daubechies 小波被选择为具有最高数量的消失矩 A(这并不意味着最好的平滑度)。使用了两种命名方案,DN 使用抽头的长度或数量,而 dbA 指的是消失矩的数量。所以D4和db2是同一个小波变换。
在本教程中,我们将使用“luispedro”图像,下面是加载它的命令。
mahotas.demos.load('luispedro')
下面是 luispedro 图像
为此,我们将使用 mahotas.idaubechies 方法
Syntax : mahotas.idaubechies(img, ‘D8’)
Argument : It takes image object and string i.e one of ‘D2’, ‘D4’, … ‘D20’ as argument
Return : It returns image object
注意:输入图像应被过滤或应加载为灰色
为了过滤图像,我们将获取图像对象 numpy.ndarray 并在索引的帮助下对其进行过滤,下面是执行此操作的命令
image = image[:, :, 0]
示例 1:
Python3
# importing various libraries
import numpy as np
import mahotas
import mahotas.demos
from mahotas.thresholding import soft_threshold
from pylab import imshow, show
from os import path
# loading image
f = mahotas.demos.load('luispedro', as_grey = True)
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(f, 'D8')
# Discard low-order bits:
t /= 8
t = t.astype(np.int8)
# showing transformed image
print("Transformed Image")
imshow(t)
show()
# reconstructed image
r = mahotas.idaubechies(t, 'D8')
# showing image
print("Reconstructed Image")
imshow(r)
show()
Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
# loading image
img = mahotas.imread('dog_image.png')
# filtering image
img = img[:, :, 0]
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(img, 'D8')
# showing transformed image
print("Transformed Image")
imshow(t)
show()
# reconstructed image
r = mahotas.idaubechies(t, 'D8')
# showing image
print("Reconstructed Image")
imshow(r)
show()
输出 :
示例 2:
Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import imshow, show
import os
# loading image
img = mahotas.imread('dog_image.png')
# filtering image
img = img[:, :, 0]
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(img, 'D8')
# showing transformed image
print("Transformed Image")
imshow(t)
show()
# reconstructed image
r = mahotas.idaubechies(t, 'D8')
# showing image
print("Reconstructed Image")
imshow(r)
show()
输出 :