Mahotas – 反转 Haar 变换
在本文中,我们将了解如何在 mahotas 中反转图像 haar 变换。 haar 小波是一系列重新缩放的“方形”函数,它们一起形成一个小波族或基。小波分析类似于傅立叶分析,因为它允许在一个区间上的目标函数以正交基表示。 Haar 序列现在被认为是第一个已知的小波基,并被广泛用作教学示例。我们可以借助 mahotas.haar 方法进行 haar 变换
在本教程中,我们将使用“luispedro”图像,下面是加载它的命令。
mahotas.demos.load('luispedro')
下面是 luispedro 图像
为此,我们将使用 mahotas.ihaar 方法
Syntax : mahotas.ihaar(haar_img)
Argument : It takes image object 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)
# haar transform
h = mahotas.haar(f)
# showing image
print("Image with haar transform")
imshow(h)
show()
# reversing haar transform
r = mahotas.ihaar(h)
# showing image
print("Reversed haar transform")
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]
# haar transform
h = mahotas.haar(img)
# showing image
print("Image with haar transform")
imshow(h)
show()
# reversing haar transform
r = mahotas.ihaar(h)
# showing image
print("Reversed haar transform")
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]
# haar transform
h = mahotas.haar(img)
# showing image
print("Image with haar transform")
imshow(h)
show()
# reversing haar transform
r = mahotas.ihaar(h)
# showing image
print("Reversed haar transform")
imshow(r)
show()
输出 :