Mahotas – 图像椭圆轴
在本文中,我们将了解如何在 mahotas 中获取图像椭圆轴。 Ellipse exes 是图像椭圆的参数,是与原始图像具有相同质量和二阶矩的等强度椭圆的参数。
对于本教程,我们将使用“lena”图像,下面是加载 lena 图像的命令
mahotas.demos.load('lena')
下面是莉娜的图片
In order to do this we will use mahotas.features.ellipse_axes method
Syntax : mahotas.features.ellipse_axes(img)
Argument : It takes image object as argument
Return : It returns two float values
注意:输入图像应被过滤或应加载为灰色
为了过滤图像,我们将获取图像对象 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 Parameters of the ‘image ellipse’
semimajor, semiminor = mahotas.features.ellipse_axes(img)
# showing value
print("Semi Major Exes : " + str(semimajor))
print("Semi Minor Exes : " + str(semiminor))
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 Parameters of the ‘image ellipse’
semimajor, semiminor = mahotas.features.ellipse_axes(img)
# showing value
print("Semi Major Exes : " + str(semimajor))
print("Semi Minor Exes : " + str(semiminor))
输出 :
Image
Semi Major Exes : 295.60277400592844
Semi Minor Exes : 295.60277400592844
另一个例子
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 Parameters of the ‘image ellipse’
semimajor, semiminor = mahotas.features.ellipse_axes(img)
# showing value
print("Semi Major Exes : " + str(semimajor))
print("Semi Minor Exes : " + str(semiminor))
输出 :
Image
Semi Major Exes : 508.79612573247636
Semi Minor Exes : 308.5809619544451