当前位置:网站首页>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 .
边栏推荐
- 二叉树创建 & 遍历
- 使用 Dumpling 备份 TiDB 集群数据到兼容 S3 的存储
- opencv学习笔记八--答题卡识别
- Parameter self-tuning of relay feedback PID controller
- Data governance: metadata management
- Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
- Flash return file download
- 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
- How to estimate the number of threads
- [KMP] template
猜你喜欢
It's hard to find a job when the industry is in recession
Pangolin Library: control panel, control components, shortcut key settings
Learn Arduino with examples
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
24. Query table data (basic)
2.10transfrom attribute
Go learning notes (3) basic types and statements (2)
Opencv learning notes 9 -- background modeling + optical flow estimation
A Closer Look at How Fine-tuning Changes BERT
From monomer structure to microservice architecture, introduction to microservices
随机推荐
edge瀏覽器 路徑獲得
Transformer principle and code elaboration
ROS learning (IX): referencing custom message types in header files
NFT smart contract release, blind box, public offering technology practice -- jigsaw puzzle
解决方案:智慧工地智能巡检方案视频监控系统
2.10transfrom attribute
Learn Arduino with examples
Onie supports pice hard disk
Opencv learning notes 8 -- answer sheet recognition
1204 character deletion operation (2)
Risk planning and identification of Oracle project management system
MFC sends left click, double click, and right click messages to list controls
What are the ways to download network pictures with PHP
好用的TCP-UDP_debug工具下载和使用
P3047 [USACO12FEB]Nearby Cows G(树形dp)
华为云OBS文件上传下载工具类
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
数据治理:数据质量篇
数据治理:误区梳理篇
Hackathon ifm