Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Adding Real-time Image Histogram Script #226

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions Image-Processing/RealTime _Image_Histogram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Image Processing

Image Processing is most commonly termed as 'Digital Image Processing' and the domain in which it is frequently used is 'Computer Vision'.
Don't be confused - we are going to talk about both of these terms and how they connect.
Both Image Processing algorithms and Computer Vision (CV) algorithms take an image as input; however, in image processing,
the output is also an image, whereas in computer vision the output can be some features/information about the image.

## OpenCV

![](https://logodix.com/logo/1989939.png)

## Installation

### Windows
$ pip install opencv-python
### MacOS
$ brew install opencv3 --with-contrib --with-python3
### Linux
$ sudo apt-get install libopencv-dev python-opencv

## Other Modules

$ pip install numpy <br>
$ pip install matplotlib

# About RealTime Image Histrogram
This script is used to make real-time image histogram with respect to RGB (Red, Green, Blue) colors. It starts with open the camera to capture the image using **opencv** module, and store it to your script directory. After that by using **numpy** and **matplotlib** it creates the histogram of image by mapping it through 256 gray scales.

# Output

![](https://github.com/gulshanbaraik01/Awesome-Python-Scripts/blob/Image-Process/Image-Processing/RealTime%20_Image_Histogram/Histogram_output.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 28 11:31:58 2020

@author: Gulshan
"""


#Importing necessary libraries for capture image and plot histrogram
import cv2
import numpy as np
from matplotlib import pyplot as plt

#Script to capture realtime image
webcam = cv2.VideoCapture(0) #Inititalize object for camera
i = 0
while i < 10:
input('Press Enter to capture')
return_value, image = webcam.read()
cv2.imwrite('realtime'+str(i)+'.png', image)
if i == i: #Break when value becomes greater than 1
break
del(webcam) #Delete camera object after capture

#Script to load realtime captured image
img = cv2.imread('realtime0.png')
color = ('b','g','r') #Create RGB Histogram
plt.figure(figsize = (10, 8))
for i, col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,256])
plt.show() #Show Histogram