当前位置:网站首页>Basic operation of color histogram
Basic operation of color histogram
2022-07-08 02:20:00 【So come on】
(1) Histogram is the intensity distribution of pixels in the image .
(2) The histogram counts the number of pixels of each intensity value .
(3)cv2.calcHist(images, channels, mask, histSize, ranges)
# 1 Import library
import cv2
import matplotlib.pyplot as plt
import numpy as np
# 2 Method : display picture
def show_image(image, title, pos):
plt.subplot(3, 2, pos)
plt.title(title)
image_RGB = image[:, :, ::-1] # BGR to RGB
plt.imshow(image_RGB)
plt.axis("off") # Axis closed
# 3 Method : Display color histogram b, g, r
def show_histogram(hist, title, pos, color):
plt.subplot(3, 2, pos)
plt.title(title)
plt.xlim([0, 256])
for h, c in zip(hist, color): # color: ('b', 'g', 'r') Tuples
plt.plot(h, color=c)
# 4 Method : Calculate the histogram
def calc_color_hist(image): # A picture came in
# b, g, r
hist = [] # An empty list , Step by step
hist.append( cv2.calcHist([image], [0], None, [256], [0, 256]))
hist.append( cv2.calcHist([image], [1], None, [256], [0, 256]))
hist.append( cv2.calcHist([image], [2], None, [256], [0, 256]))
return hist
# 5 The main function
def main():
# 5.1 Create a canvas
plt.figure(figsize=(12, 8))
plt.suptitle("Color Histogram", fontsize=10, fontweight="bold")
# 5.2 Read original picture
img = cv2.imread("children.jpg")
# 5.3 Calculate the histogram
img_hist = calc_color_hist(img)
# 5.4 Display pictures and histograms
show_image(img, "RGB Image", 1)
show_histogram(img_hist, "RGB Image Hist", 2, ('b', 'g', 'r')) # Pass a tuple bgr, No m
# 5.5 Each pixel in the original picture increases 50 Pixel values
M = np.ones(img.shape, dtype="uint8") * 50
added_image = cv2.add(img, M) # Pixels are added one by one
added_image_hist = calc_color_hist(added_image)
show_image(added_image, 'added image', 3)
show_histogram(added_image_hist, 'added image hist', 4, ('b', 'g', 'r'))
# 5.6 Subtract... From each pixel in the original picture 50 Pixel values
subtracted_image = cv2.subtract(img, M)
subtracted_image_hist = calc_color_hist(subtracted_image)
show_image(subtracted_image, 'subtracted image', 5)
show_histogram(subtracted_image_hist, 'subtracted image hist', 6, ('b', 'g', 'r'))
plt.show()
if __name__ == '__main__':
main()
边栏推荐
- 数据链路层及网络层协议要点
- 实现前缀树
- Force buckle 6_ 1342. Number of operations to change a number to 0
- Yolo fast+dnn+flask realizes streaming and streaming on mobile terminals and displays them on the web
- mysql报错ORDER BY clause is not in SELECT list, references column ‘‘which is not in SELECT list解决方案
- leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
- JVM memory and garbage collection -4-string
- 喜欢测特曼的阿洛
- CorelDRAW2022下载安装电脑系统要求技术规格
- Semantic segmentation | learning record (3) FCN
猜你喜欢
Discrimination gradient descent
Strive to ensure that domestic events should be held as much as possible, and the State General Administration of sports has made it clear that offline sports events should be resumed safely and order
Little knowledge about TXE and TC flag bits
非分区表转换成分区表以及注意事项
Semantic segmentation | learning record (5) FCN network structure officially implemented by pytoch
Deeppath: a reinforcement learning method of knowledge graph reasoning
COMSOL --- construction of micro resistance beam model --- final temperature distribution and deformation --- addition of materials
OpenGL/WebGL着色器开发入门指南
leetcode 873. Length of Longest Fibonacci Subsequence | 873. 最长的斐波那契子序列的长度
Clickhouse principle analysis and application practice "reading notes (8)
随机推荐
VR/AR 的产业发展与技术实现
JVM memory and garbage collection -4-string
Leetcode question brushing record | 283_ Move zero
leetcode 866. Prime Palindrome | 866. prime palindromes
Clickhouse principle analysis and application practice "reading notes (8)
咋吃都不胖的朋友,Nature告诉你原因:是基因突变了
Talk about the realization of authority control and transaction record function of SAP system
数据链路层及网络层协议要点
[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning
Force buckle 5_ 876. Intermediate node of linked list
阿锅鱼的大度
Spock单元测试框架介绍及在美团优选的实践_第三章(void无返回值方法mock方式)
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.2 data preprocessing_ Learning thinking and exercise answers
Learn CV two loss function from scratch (2)
魚和蝦走的路
leetcode 873. Length of Longest Fibonacci Subsequence | 873. 最长的斐波那契子序列的长度
Xiaobai tutorial: Raspberry pie 3b+onnxruntime+scrfd+flask to realize public face detection system
Neural network and deep learning-5-perceptron-pytorch
Dnn+yolo+flask reasoning (raspberry pie real-time streaming - including Yolo family bucket Series)
UFS Power Management 介绍