Gamma校正

Gamma校正是对输入图像灰度值进行的非线性操作,使输出图像灰度值与输入图像灰度值呈指数关系:

这个指数即为Gamma。

Gamma校正的原理很简单,就一个很简单的表达式,如下图所示:

其中V_in的取值范围是0~1,最重要的参数就是公式中的γ参数!

γ的值决定了输入图像和输出图像之间的灰度映射方式,即决定了是增强低灰度值区域还是增高灰度值区域。

γ>1时,图像的高灰度区域对比度得到增强。

γ<1时,图像的低灰度区域对比度得到增强。

γ=1时,不改变原图像。

伽马变换对于图像对比度偏低,并且整体亮度值偏高(对于于相机过曝)情况下的图像增强效果明显。

对数log变换

log 函数的表达式:

y=alog(1+x), a 是一个放大系数,x 同样是输入的像素值,取值范围为 [0−1], y 是输出的像素值。

对数变换对于整体对比度偏低并且灰度值偏低的图像增强效果较好。

skimage库实现gamam校正和log校正

函数:

Gamma:

gamma_corrected = exposure.adjust_gamma(img, 2)

Logarithmic:

logarithmic_corrected = exposure.adjust_log(img, 1)

"""

=================================

Gamma and log contrast adjustment

=================================

This example adjusts image contrast by performing a Gamma and a Logarithmic

correction on the input image.

"""

import matplotlib

import matplotlib.pyplot as plt

import numpy as np

from skimage import data, img_as_float

from skimage import exposure

matplotlib.rcParams['font.size'] = 8

def plot_img_and_hist(image, axes, bins=256):

"""Plot an image along with its histogram and cumulative histogram.

"""

image = img_as_float(image)

ax_img, ax_hist = axes

ax_cdf = ax_hist.twinx()

# Display image

ax_img.imshow(image, cmap=plt.cm.gray)

ax_img.set_axis_off()

# Display histogram

ax_hist.hist(image.ravel(), bins=bins, histtype='step', color='black')

ax_hist.ticklabel_format(axis='y', style='scientific', scilimits=(0, 0))

ax_hist.set_xlabel('Pixel intensity')

ax_hist.set_xlim(0, 1)

ax_hist.set_yticks([])

# Display cumulative distribution

img_cdf, bins = exposure.cumulative_distribution(image, bins)

ax_cdf.plot(bins, img_cdf, 'r')

ax_cdf.set_yticks([])

return ax_img, ax_hist, ax_cdf

# Load an example image

img = data.moon()

# Gamma

gamma_corrected = exposure.adjust_gamma(img, 2)

# Logarithmic

logarithmic_corrected = exposure.adjust_log(img, 1)

# Display results

fig = plt.figure(figsize=(8, 5))

axes = np.zeros((2, 3), dtype=np.object)

axes[0, 0] = plt.subplot(2, 3, 1)

axes[0, 1] = plt.subplot(2, 3, 2, sharex=axes[0, 0], sharey=axes[0, 0])

axes[0, 2] = plt.subplot(2, 3, 3, sharex=axes[0, 0], sharey=axes[0, 0])

axes[1, 0] = plt.subplot(2, 3, 4)

axes[1, 1] = plt.subplot(2, 3, 5)

axes[1, 2] = plt.subplot(2, 3, 6)

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0])

ax_img.set_title('Low contrast image')

y_min, y_max = ax_hist.get_ylim()

ax_hist.set_ylabel('Number of pixels')

ax_hist.set_yticks(np.linspace(0, y_max, 5))

ax_img, ax_hist, ax_cdf = plot_img_and_hist(gamma_corrected, axes[:, 1])

ax_img.set_title('Gamma correction')

ax_img, ax_hist, ax_cdf = plot_img_and_hist(logarithmic_corrected, axes[:, 2])

ax_img.set_title('Logarithmic correction')

ax_cdf.set_ylabel('Fraction of total intensity')

ax_cdf.set_yticks(np.linspace(0, 1, 5))

# prevent overlap of y-axis labels

fig.tight_layout()

plt.show()

实验结果

python图片矫正后对比_python库skimage 对图像进行gamma校正和log校正相关推荐

  1. python图片风格迁移毕设_Python简单实现图像风格迁移

    下载W3Cschool手机App,0基础随时随地学编程导语 T_T之前似乎发过类似的文章,那时候是用Keras实现的,现在用的PyTorch,而且那时候发的内容感觉有些水,于是我决定... 好吧我确实 ...

  2. python图片批量重命名_python实现大量图片重命名

    本文实例为大家分享了python实现大量图片重命名的具体代码,供大家参考,具体内容如下 说明 在进行深度学习的过程中,需要对图片进行批量的命名处理,因此利用简单的python代码实现图片的命名格式处理 ...

  3. python图片修复软件下载_python 实现图片修复(可用于去水印)

    在现实的生活中,我们可能会遇到一些美好的或是珍贵的图片被噪声干扰,比如旧照片的折痕,比如镜头上的灰尘或污渍,更或者是某些我们想为我所用但有讨厌水印,那么有没有一种办法可以消除这些噪声呢? 答案是肯定的 ...

  4. php gd2图片保存,PHP使用GD2库生成的图像无法输出的解决方法

    前言 有时候我们可能随意的使用php跟GD库来创建一张图片,可能是用于展示验证码之类的. 官方代码如下:Note: 此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本).< ...

  5. python canny函数_python库skimage 应用canny边缘探测算法

    Canny算法 skimage库中函数 skimage.feature.canny(image, sigma=1.0, low_threshold=None, high_threshold=None, ...

  6. python 灰度图像_python库skimage 给灰度图像染色

    灰度图像染成红色和黄色 # 1.将灰度图像转换为RGB图像 image = color.gray2rgb(grayscale_image) # 2.保留红色分量和黄色分量 red_multiplier ...

  7. python图片显示英文字符_Python中利用Tesseract软件来识别图片中的英文与中文

    OCR与Tesseract介绍 将图片翻译成文字一般被称为光学文字识别(Optical Character Recognition,OCR).可以实现OCR 的底层库并不多,目前很多库都是使用共同的几 ...

  8. python和javascript详细对比_python与javascript 引入模块的方法对比

    1.引入整体模块对比 python 方法一: #引入全部函数 from xxx import * #直接使用模块里面的各函数或者属性 test() 方法二: #引入全局的模块 importglobal ...

  9. python是谁维护的_Python 库从开发到维护

    每个法师都有一颗近战的心,每个 CS 学生都有开发一个算法库的小目标- 前言 在学习和开发过程中,笔者发现项目开发和库开发有很大不同的,下面从 __init__.py .单元测试.README.测试. ...

最新文章

  1. Unity初学Shadergraph创建着色器学习教程
  2. python读取一个文件夹/子文件夹下的所有文件名字
  3. 下载r包IlluminaHumanMethylation450kanno.ilmn12.hg19
  4. Linux系统中的防火墙的实现:iptables/netfilter
  5. 第一次正经面试之发现自己的缺陷和不足
  6. Android之三大图片缓存原理、特性对比
  7. dw服务器文件夹在哪里,Dreamweaver CC
  8. NOIP2016普及组第一题:买铅笔
  9. 胡巴小年调皮搞事情?嗨翻五城华为体验店
  10. Arcgis栅格时序地图制作---时间轴动态展示多期影像
  11. RejectedExecutionException 分析
  12. Swagger注解说明
  13. 绘制相同到期日欧式期权组合收益图(python)
  14. 2021-2024年中国两轮电动车企业经营情况对比
  15. 计算机科班生学计算机组成原理的意义何在呢?
  16. 相机标定(笔记本摄像头和usb相机)
  17. Excel怎么一次性删除数据末尾的空格
  18. 蓝精灵事件来袭: 深受喜爱的蓝色角色来 Web3 啦!
  19. 各国疫苗接种进度(气泡图可视化)
  20. SYSTEM_INFO

热门文章

  1. Android教程 -07 Activity的任务栈和启动模式
  2. JavaScript原生对象属性和方法详解——Date对象
  3. container_of宏定义分析---linux内核
  4. .Net程序员学习Linux最简单的方法
  5. 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序 解决方案
  6. 【PPT分享】阿里巴巴定向广告之新一代Rank技术.pdf(附下载链接)
  7. 对于Neural ODE的小研究
  8. 全球首发!惯性导航导论(剑桥大学)第六部分
  9. 西门子v90伺服说明书_西门子V90伺服驱动器的的EPOS控制模式
  10. centos7修改ip地址自动获取_南京课工场IT培训:如何搭建DHCP服务器及自动获取IP地址及相关操作...