当前位置:网站首页>1. Color inversion, logarithmic transformation, gamma transformation source code - miniopencv from zero
1. Color inversion, logarithmic transformation, gamma transformation source code - miniopencv from zero
2022-07-06 07:59:00 【The story has turned several pages】
From scratch MiniOpenCV——1. Color reversal , Logarithmic transformation , Gamma transform source code
Build your own from scratch mini edition opencv, Know the principle of various image transformations from the bottom , Have a deeper understanding of digital image processing .
The environment is python3.6
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider,Button,RadioButtons
def set_chinese():
""" To make sure to show Chinese in plot """
import matplotlib
matplotlib.rcParams['font.sans-serif']=['SimHei']
matplotlib.rcParams['axes.unicode_minus']=False
def image_inverse(input):
""" The function of invert color transformation, The input is an array of numpy. """
value_max = np.max(input)
output = value_max - input
return output
def image_log(input):
""" Name:log transform, Params:input is an array of numpy. Function: Compress the dynamic range to show more image detail. """
return np.log(1+input)
# For more information, please follow wechat GongZhonghao“ The story of endless stories ”
def gamma_trans(input, gamma=2, eps=0.5):
""" Name:gamma transform, params: input is an array of numpy; eps is a supplement. Function: Extend the dynamic range, increase image contrast and show more images' detail. Useage:CRT correction. """
return 255. * (((input + eps)/255.) ** gamma)
def update_gamma(val):
gamma = slider1.val
output = gamma_trans(img, gamma=gamma, eps=0.5)
print("--------\n", output)
ax1.set_title(" After gamma transformation ,gamma = " + str(gamma))
ax1.imshow(output, cmap='gray', vmin=0, vmax=255)
if __name__ == "__main__":
""" x1 and x2 The random matrix of , Whether its dynamic range is greater than 256 Still less than 256, The values in the matrix , Map equally to 0-255 It shows that , This is a matplotlib In the library , imshow(),save() The default operation , The same is true of other drawing libraries . """
set_chinese()
img = np.asarray(Image.open("img.jpg").convert("L"))
fig = plt.figure()
ax0 = fig.add_subplot(121)
ax0.set_title(" Input matrix ")
ax0.imshow(img, cmap='gray', vmin=0,vmax=255)
ax1 = fig.add_subplot(122)
plt.subplots_adjust(bottom=0.3)
s1 = plt.axes([0.25,0.1,0.55,0.03], facecolor='lightgoldenrodyellow') # Parameters of slider
slider1 = Slider(s1, ' Parameters gamma',0.0,2.0,valfmt="%.f",valinit=1.0,valstep=0.1)
slider1.on_changed(update_gamma)# Monitoring methods
slider1.reset()
slider1.set_val(1)
plt.show()
The author just follows others' online tutorials , Some improvements have been made .
Follow up on this column .
The key points have been commented , Please feel free to let me know if you have any questions .
边栏推荐
- 22. Empty the table
- Data governance: Data Governance under microservice architecture
- Transformer principle and code elaboration
- [Yugong series] February 2022 U3D full stack class 010 prefabricated parts
- Linked list interview questions (Graphic explanation)
- CAD ARX 获取当前的视口设置
- Le chemin du navigateur Edge obtient
- 将 NFT 设置为 ENS 个人资料头像的分步指南
- 数据治理:元数据管理篇
- 【云原生】手把手教你搭建ferry开源工单系统
猜你喜欢
![08- [istio] istio gateway, virtual service and the relationship between them](/img/fb/09793f5fd12c2906b73cc42722165f.jpg)
08- [istio] istio gateway, virtual service and the relationship between them
![[nonlinear control theory]9_ A series of lectures on nonlinear control theory](/img/a8/03ed363659a0a067c2f1934457c106.png)
[nonlinear control theory]9_ A series of lectures on nonlinear control theory

将 NFT 设置为 ENS 个人资料头像的分步指南

Chinese Remainder Theorem (Sun Tzu theorem) principle and template code

指针和数组笔试题解析
![[untitled]](/img/38/bc025310b9742b5bf0bd28c586ec0d.jpg)
[untitled]

IP lab, the first weekly recheck

Leetcode question brushing record | 203_ Remove linked list elements

Codeforces Global Round 19(A~D)

opencv学习笔记八--答题卡识别
随机推荐
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
Opencv learning notes 9 -- background modeling + optical flow estimation
Circuit breaker: use of hystrix
Learn Arduino with examples
Iterator Foundation
wincc7.5下载安装教程(Win10系统)
Golang DNS write casually
It's hard to find a job when the industry is in recession
C语言自定义类型:结构体
649. Dota2 Senate
Position() function in XPath uses
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
实现精细化生产, MES、APS、ERP必不可少
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
PHP - Common magic method (nanny level teaching)
What are the ways to download network pictures with PHP
Data governance: data quality
861. Score after flipping the matrix
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
远程存储访问授权