当前位置:网站首页>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 .
边栏推荐
- flask返回文件下载
- Common functions for PHP to process strings
- "Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
- 21. Delete data
- File upload of DVWA range
- Easy to use tcp-udp_ Debug tool download and use
- edge浏览器 路径获得
- Document 2 Feb 12 16:54
- MySQL view tablespace and create table statements
- Hill sort c language
猜你喜欢

C语言自定义类型:结构体

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
![[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems](/img/6d/282d904810807810adb06b071fb39b.jpg)
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems

Easy to use tcp-udp_ Debug tool download and use

Make learning pointer easier (3)

Sanzi chess (C language)
![[cf gym101196-i] waif until dark network maximum flow](/img/66/6b339fc23146b5fbdcd2a1fa0a2349.png)
[cf gym101196-i] waif until dark network maximum flow

National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund

How to prevent Association in cross-border e-commerce multi account operations?

【T31ZL智能视频应用处理器资料】
随机推荐
. Net 6 learning notes: what is NET Core
matplotlib. Widgets are easy to use
Nc204382 medium sequence
解决方案:智慧工地智能巡檢方案視頻監控系統
Analysis of Top1 accuracy and top5 accuracy examples
edge瀏覽器 路徑獲得
Common functions for PHP to process strings
JS select all and tab bar switching, simple comments
2.10transfrom attribute
Step by step guide to setting NFT as an ens profile Avatar
图像融合--挑战、机遇与对策
软件开发的一点随记
How to prevent Association in cross-border e-commerce multi account operations?
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
24. Query table data (basic)
Leetcode question brushing record | 203_ Remove linked list elements
实现精细化生产, MES、APS、ERP必不可少
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
649. Dota2 Senate
Binary tree creation & traversal