如何使用PIL \ Numpy在Python中获取灰度图像的平均像素值?

编程入门 行业动态 更新时间:2024-10-26 16:28:45
本文介绍了如何使用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中获取灰度图像的平均像素值?

本文发布于:2023-06-08 06:34:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/576197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:灰度   如何使用   像素   图像   平均

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!