python opencv图像对比度增强_在python(cv2)中使用OpenCV增加彩色图像对比度的最快方法是什么?...

本文介绍了在Python中使用OpenCV通过简单的numpy数组算术进行图像对比度增强的方法。通过调整参数,实现了图像的亮度增加和减少,从而达到增强对比度的效果。通过示例代码展示了如何操作,并附带了图像变换的示意图。
摘要由CSDN通过智能技术生成

正如Abid Rahaman K评论的那样,numpy数组中的简单算术是最快的.

这是一些类似于亮度/对比度操作的图像处理:

'''

Simple and fast image transforms to mimic:

- brightness

- contrast

- erosion

- dilation

'''

import cv2

from pylab import array, plot, show, axis, arange, figure, uint8

# Image data

image = cv2.imread('imgur.png',0) # load as 1-channel 8bit grayscale

cv2.imshow('image',image)

maxIntensity = 255.0 # depends on dtype of image data

x = arange(maxIntensity)

# Parameters for manipulating image data

phi = 1

theta = 1

# Increase intensity such that

# dark pixels become much brighter,

# bright pixels become slightly bright

newImage0 = (maxIntensity/phi)*(image/(maxIntensity/theta))**0.5

newImage0 = array(newImage0,dtype=uint8)

cv2.imshow('newImage0',newImage0)

cv2.imwrite('newImage0.jpg',newImage0)

y = (maxIntensity/phi)*(x/(maxIntensity/theta))**0.5

# Decrease intensity such that

# dark pixels become much darker,

# bright pixels become slightly dark

newImage1 = (maxIntensity/phi)*(image/(maxIntensity/theta))**2

newImage1 = array(newImage1,dtype=uint8)

cv2.imshow('newImage1',newImage1)

z = (maxIntensity/phi)*(x/(maxIntensity/theta))**2

# Plot the figures

figure()

plot(x,y,'r-') # Increased brightness

plot(x,x,'k:') # Original image

plot(x,z, 'b-') # Decreased brightness

#axis('off')

axis('tight')

show()

# Close figure window and click on other window

# Then press any keyboard key to close all windows

closeWindow = -1

while closeWindow<0:

closeWindow = cv2.waitKey(1)

cv2.destroyAllWindows()

灰度原始图像:

变亮的图像似乎是膨胀的:

变暗的图像似乎被侵蚀,锐化,具有更好的对比度:

像素强度如何变换:

如果你玩phi和theta的值,你会得到非常有趣的结果.您还可以为多通道图像数据实现此技巧.

—编辑—

看看this youtube video上“水平”和“曲线”的概念,在photoshop中显示图像编辑.线性变换的等式产生相同的量,即每个像素的变化“水平”.如果您编写一个可以区分像素类型的方程式(例如那些已经具有特定值的方程式),那么您可以根据该方程式描述的“曲线”更改像素.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值