该参数的计算可用于图像分割领域
首先,导入图片
img = io.imread('846f089b1733d5227094e5cc68f1ffb1_.png', as_gray=True)
之后,对其进行数组化处理,将图像转化为数组,彩色图像为三维数组,有红、绿、蓝三个通道;灰度图像为二维数组,没有颜色信息。将图像转换为数组之后,可以对其进行任意数学操作,达到处理图像的目的。
img_array = np.array(img)
最后,分别用np.mean()、np.var()、np.std()对该数组进行处理分别得到数组的均值、方差与标准差
import numpy as np
from matplotlib import pyplot as plt
from skimage import io
img = io.imread('846f089b1733d5227094e5cc68f1ffb1_.png', as_gray=True)
# io.imshow(img)
# io.show()
img_array = np.array(img)
mean_value = np.mean(img_array) # 计算均值
variance_value = np.var(img_array) # 计算方差
std_value = np.std(img_array) # 计算标准差
print("图像像素均值是:", mean_value)
print("图像像素方差是:", variance_value)
print("图像像素标准差是:", std_value)