当前位置:网站首页>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 .
边栏推荐
- Description of octomap averagenodecolor function
- NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
- onie支持pice硬盘
- edge瀏覽器 路徑獲得
- 上线APS系统,破除物料采购计划与生产实际脱钩的难题
- [KMP] template
- MFC 给列表控件发送左键单击、双击、以及右键单击消息
- C语言自定义类型:结构体
- Redis list detailed explanation of character types yyds dry goods inventory
- 649. Dota2 Senate
猜你喜欢
Golang DNS write casually
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
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems
hcip--mpls
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
珠海金山面试复盘
指针和数组笔试题解析
Document 2 Feb 12 16:54
Go learning notes (3) basic types and statements (2)
Description of octomap averagenodecolor function
随机推荐
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
Redis list detailed explanation of character types yyds dry goods inventory
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Analysis of Top1 accuracy and top5 accuracy examples
Vit (vision transformer) principle and code elaboration
Golang DNS 随便写写
Opencv learning notes 9 -- background modeling + optical flow estimation
二叉树创建 & 遍历
edge浏览器 路径获得
861. Score after flipping the matrix
1202 character lookup
"Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco
华为云OBS文件上传下载工具类
File upload of DVWA range
Linked list interview questions (Graphic explanation)
数据治理:微服务架构下的数据治理
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
PHP - Common magic method (nanny level teaching)
Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University