📜  Mahotas – 图像的圆度

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

Mahotas – 图像的圆度

在本文中,我们将了解如何在 mahotas 中获得图像圆度特征。圆度取决于形状的总体特征,而不是其边缘和角落的定义,或制造对象的表面粗糙度。如果偏心率大,光滑椭圆的圆度可能会很低
对于本教程,我们将使用“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()
 
# computing roundness in image
value = mahotas.features.roundness(img)
  
 
# printing value
print("Roundness : " + str(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()
 
# computing roundness in image
value = mahotas.features.roundness(img)
  
 
# printing value
print("Roundness : " + str(value))


输出 :

Image

Roundness : 0.0

另一个例子

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()
 
# computing roundness in image
value = mahotas.features.roundness(img)
  
 
# printing value
print("Roundness : " + str(value))

输出 :

Image

Roundness : 0.04297201733896709