Mahotas – 使用 Daubechies 小波变换图像
在本文中,我们将了解如何在 mahotas 中使用 daubechies 小波变换图像。一般来说,对于给定的支持宽度 2A,Daubechies 小波被选择为具有最高数量的消失矩(这并不意味着最好的平滑度)。使用了两种命名方案,DN 使用抽头的长度或数量,而 dbA 指的是消失矩的数量。所以D4和db2是同一个小波变换。
在本教程中,我们将使用“luispedro”图像,下面是加载它的命令。
mahotas.demos.load('luispedro')
下面是 luispedro 图像
为此,我们将使用 mahotas.daubechies 方法
Syntax : mahotas.daubechies(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 matplotlib import pyplot as plt
from os import path
# loading image
f = mahotas.demos.load('luispedro', as_grey = True)
# making ply gray
plt.gray()
# showing image
print("Image")
plt.imshow(f)
plt.show()
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(f, 'D8')
# showing transformed image
print("Transformed Image")
plt.imshow(t)
plt.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]
# showing image
print("Image")
imshow(img)
show()
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(img, 'D8')
# showing transformed image
print("Transformed Image")
imshow(t)
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]
# showing image
print("Image")
imshow(img)
show()
# Transform using D8 Wavelet to obtain transformed image t
t = mahotas.daubechies(img, 'D8')
# showing transformed image
print("Transformed Image")
imshow(t)
show()
输出 :