python拖拽显示直方图

2021/12/11 14:18:51

本文主要是介绍python拖拽显示直方图,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

https://blog.csdn.net/lanlanmingyue/article/details/102745376
python3.8

安装依赖

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pillow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib

zft.py

# -*- coding: utf-8 -*-

import sys

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

src = Image.open(sys.argv[1])
r,g,b = src.split() #分离R\G\B

plt.figure("flowerHist")
#要对图像求直方图,就需要先把图像矩阵进行flatten操作,使之变为一维数组,然后再进行统计
#分别提取R\G\B统计值,叠加绘图
ar = np.array(r).flatten() 
plt.hist(ar,bins = 256, density = 1, facecolor = 'red', edgecolor = 'red',stacked=True)

ag = np.array(g).flatten()
plt.hist(ag,bins = 256, density = 1, facecolor = 'green', edgecolor = 'green',stacked=True)

ab = np.array(b).flatten()
plt.hist(ab,bins = 256, density = 1, facecolor = 'blue', edgecolor = 'blue', stacked=True)

plt.show()




这篇关于python拖拽显示直方图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程