Mahotas – 获取图像时刻
在本文中,我们将了解如何在 mahotas 中创建图像时刻。在图像处理、计算机视觉和相关领域中,图像矩是图像像素强度的某个特定加权平均值,或此类矩的函数,通常选择具有某些有吸引力的属性或解释。图像矩对于描述分割后的对象很有用。
在本教程中,我们将使用“Lena”图像,下面是加载它的命令。
mahotas.demos.load('lena')
下面是莉娜的图片
In order to do this we will use mahotas.moments method
Syntax : mahotas.moments(img, p0, p1)
Argument : It takes image object and two float values as argument
Return : It returns image object
注意:输入图像应被过滤或加载为灰色
为了过滤图像,我们将获取图像对象 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()
# Power for first dimension
p0 = 5.5
# Power for second dimension
p1 = 5.5
# getting moments
moment = mahotas.moments(img, p0, p1)
# printing moments
print("Moment value = " + str(moment))
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()
# Power for first dimension
p0 = 10.5
# Power for second dimension
p1 = 2.5
# getting moments
moment = mahotas.moments(img, p0, p1)
# printing moments
print("Moment value = " + str(moment))
输出 :
Image
Moment value = 6.784986531904299e+35
另一个例子
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()
# Power for first dimension
p0 = 10.5
# Power for second dimension
p1 = 2.5
# getting moments
moment = mahotas.moments(img, p0, p1)
# printing moments
print("Moment value = " + str(moment))
输出 :
Image
Moment value = 1.5229432312149368e+42