GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencv-code/display-histogram.py at master · cppAndNetworkAndDB/opencv-code

Expand file tree

/

display-histogram.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
33 lines (27 loc) · 810 Bytes
/

display-histogram.py

Copy path

File metadata and controls

33 lines (27 loc) · 810 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
"""
Sample code for displaying image histogram with Matplotlib
"""
import cv2
import matplotlib.pyplot as plt
def show_histogram(im):
""" Function to display image histogram.
Supports single and three channel images. """
if im.ndim == 2:
# Input image is single channel
plt.hist(im.flatten(), 256, range=(0,250), fc='k')
plt.show()
elif im.ndim == 3:
# Input image is three channels
fig = plt.figure()
fig.add_subplot(311)
plt.hist(im[...,0].flatten(), 256, range=(0,250), fc='b')
fig.add_subplot(312)
plt.hist(im[...,1].flatten(), 256, range=(0,250), fc='g')
fig.add_subplot(313)
plt.hist(im[...,2].flatten(), 256, range=(0,250), fc='r')
plt.show()
if __name__ == '__main__':
im = cv2.imread("lena.jpg");
if not (im == None):
show_histogram(im)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.