以下是使用 Python 统计 BMP 图像每一列的均值的示例代码:

import numpy as np
from PIL import Image

# 读取 BMP 图像
img = Image.open('image.bmp')
# 转为 NumPy 数组
img_arr = np.array(img)
# 计算均值
mean_arr = np.mean(img_arr, axis=0)

# 输出每一列的均值
for i in range(mean_arr.shape[0]):
    print('第%d列的均值为%.2f' % (i+1, mean_arr[i]))

说明:

  1. 代码使用 NumPy 库读取 BMP 图像,并将图像转为 NumPy 数组。
  2. 使用 np.mean 函数计算每一列的均值,axis=0 表示计算每一列的均值。
  3. 循环输出每一列的均值。

注意:代码中的 image.bmp 应替换为实际 BMP 图像的文件名。

Python 统计 BMP 图像每一列的均值

原文地址: https://www.cveoy.top/t/topic/ndRp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录