📜  Mahotas – 泽尼克时刻

📅  最后修改于: 2022-05-13 01:55:01.715000             🧑  作者: Mango

Mahotas – 泽尼克时刻

在本文中,我们将了解如何在 mahotas 中获取给定图像的 Zernike 矩。 Zernike 多项式是一个正交基组(一组函数,其中任何一对函数的乘积的积分为零)。在图像处理、计算机视觉和相关领域中,图像矩是图像像素强度的某个特定加权平均值,或此类矩的函数,通常选择具有某些有吸引力的属性或解释。图像矩对于描述分割后的对象很有用。
在本教程中,我们将使用“Lena”图像,下面是加载 Lena 图像的命令

mahotas.demos.load('lena')

下面是莉娜的图片

注意:输入图像应被过滤或加载为灰色
为了过滤图像,我们将获取图像对象 numpy.ndarray 并在索引的帮助下对其进行过滤,下面是执行此操作的命令

image = image[:, :, 0]

下面是实现

Python3
# importing required libraries
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
import matplotlib.pyplot as plt
   
# loading image
img = mahotas.demos.load('lena')
   
# filtering image
img = img.max(2)
 
print("Image")
   
# showing image
imshow(img)
show()
 
# radius
radius = 10
 
# computing zernike moments
value = mahotas.features.zernike_moments(img, radius)
  
 
# printing value
print(value)


Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
import matplotlib.pyplot as plt
  
# loading image
img = mahotas.imread('dog_image.png')
 
 
# filtering image
img = img[:, :, 0]
   
print("Image")
   
# showing image
imshow(img)
show()
 
# radius
radius = 10
 
# computing zernike moments
value = mahotas.features.zernike_moments(img, radius)
  
 
# printing value
print(value)


输出 :

Image

[0.31830989 0.01261485 0.00614926 0.00769591 0.0097145  0.01757332
 0.00617458 0.01008905 0.01415304 0.01099679 0.02894761 0.01838737
 0.0074247  0.01333135 0.01958184 0.00431827 0.00540781 0.01675913
 0.03511082 0.00699177 0.00357231 0.01593838 0.01621848 0.0240565
 0.0154929 ]

另一个例子

Python3

# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
import matplotlib.pyplot as plt
  
# loading image
img = mahotas.imread('dog_image.png')
 
 
# filtering image
img = img[:, :, 0]
   
print("Image")
   
# showing image
imshow(img)
show()
 
# radius
radius = 10
 
# computing zernike moments
value = mahotas.features.zernike_moments(img, radius)
  
 
# printing value
print(value)

输出 :

Image

[0.31830989 0.00985427 0.00714652 0.00171408 0.00442245 0.01796711
 0.00716781 0.00179965 0.0039829  0.0031081  0.02447476 0.0011686
 0.009291   0.00174885 0.00357579 0.00692029 0.0043969  0.03528869
 0.00264739 0.01381883 0.00750501 0.0036528  0.00867514 0.01298398
 0.0129556 ]