Mahotas – 图像的偏心
在本文中,我们将了解如何在 mahotas 中获得图像的偏心率。偏心率测量从给定顶点 v 到连通图的任何其他顶点 w 的最短路径长度。为每个顶点 v 计算,它将图的连接结构转换为一组值。对于数字图像的连接区域,它是通过其邻域图和给定度量来定义的。
mahotas.demos.load('lena')
下面是莉娜的图片
In order to do this we will use mahotas.features.eccentricity( method
Syntax : mahotas.features.eccentricity(img)
Argument : It takes image object as argument
Return : It returns float value
注意:输入图像应被过滤或应加载为灰色
为了过滤图像,我们将获取图像对象 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 eccentricity value
value = mahotas.features.eccentricity(img)
# showing value
print("Eccentricity value = " + 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 eccentricity value
value = mahotas.features.eccentricity(img)
# showing value
print("Eccentricity value = " + str(value))
输出 :
Image
Eccentricity value = 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 eccentricity value
value = mahotas.features.eccentricity(img)
# showing value
print("Eccentricity value = " + str(value))
输出 :
Image
Eccentricity value = 0.7950893156644899