当前位置:网站首页>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 .
边栏推荐
- CAD ARX gets the current viewport settings
- 49. Sound card driven article collection
- 在 uniapp 中使用阿里图标
- The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
- 你想知道的ArrayList知识都在这
- 649. Dota2 Senate
- NFT smart contract release, blind box, public offering technology practice -- contract
- Description of octomap averagenodecolor function
- 使用 TiUP 升级 TiDB
- Redis list detailed explanation of character types yyds dry goods inventory
猜你喜欢
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Interview Reply of Zhuhai Jinshan
IP lab, the first weekly recheck
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
【云原生】手把手教你搭建ferry开源工单系统
链表面试题(图文详解)
MEX有关的学习
File upload of DVWA range
Golang DNS write casually
随机推荐
Redis list detailed explanation of character types yyds dry goods inventory
Sanzi chess (C language)
861. Score after flipping the matrix
How to estimate the number of threads
From monomer structure to microservice architecture, introduction to microservices
07- [istio] istio destinationrule (purpose rule)
Iterator Foundation
Notes on software development
The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat
onie支持pice硬盘
NFT smart contract release, blind box, public offering technology practice -- contract
Common functions for PHP to process strings
What are the ways to download network pictures with PHP
Pangolin Library: control panel, control components, shortcut key settings
二叉树创建 & 遍历
JS select all and tab bar switching, simple comments
1204 character deletion operation (2)
Le chemin du navigateur Edge obtient
Understanding of law of large numbers and central limit theorem
esRally国内安装使用避坑指南-全网最新