本文介绍了如何使用PIL \ Numpy在Python中获取灰度图像的平均像素值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的灰度图像很少,因此我考虑了计算整个图像的平均像素值,以便可以使用单个值表示每个单独的图像.
I have few gray scale images and I thought of calculating the average pixel value of the total image, so that I can represent each individual image using a single value.
推荐答案
如果要执行此类操作,则应考虑使用scikit-image而不是原始的PIL或枕头. SciKit Image使用numpy数组存储图像,因此所有numpy方法都可以使用.
If you want to do stuff like this, you should consider using scikit-image instead of raw PIL or pillow. SciKit Image uses numpy arrays for images, so all the numpy methods work.
from skimage import io import numpy as np image = io.imread('i.stack.imgur/Y8UeF.jpg') print(np.mean(image))您可能希望将所有图像都转换为float值,以获取0和1之间的值:
You might want to convert all images to float to get a value betwenn 0 and 1:
from skimage import io, img_as_float import numpy as np image = io.imread('i.stack.imgur/Y8UeF.jpg') image = img_as_float(image) print(np.mean(image))更多推荐
如何使用PIL \ Numpy在Python中获取灰度图像的平均像素值?
发布评论