44. 图像的灰度变换(伽马变换)

2025-06-27  本文已影响0人  大龙10

灰度变换与直方图索引

一、线性灰度变换

二、伽马变换

三、例程

import cv2
import numpy as np
from matplotlib import pyplot as plt

# 1.56 图像的非线性灰度变换: 幂律变换 (伽马变换)
img = cv2.imread(r"e:/opencv/bgra.png", flags=0)  # flags=0 读取为灰度图像

gammaList = [0.125, 0.25, 0.5, 1.0, 2.0, 4.0]  # gamma 值
normImg = lambda x: 255. * (x-x.min()) / (x.max()-x.min()+1e-6)  # 归一化为 [0,255]

plt.figure(figsize=(9,6))
for k in range(len(gammaList)):
imgGamma = np.power(img, gammaList[k])
imgGamma = np.uint8(normImg(imgGamma))

plt.subplot(2, 3, k+1), plt.axis('off')
plt.imshow(imgGamma,  cmap='gray', vmin=0, vmax=255)
plt.title(f"$\gamma={gammaList[k]}$")
plt.show()

四、资料

youcans_的博客:
https://blog.csdn.net/youcans/article/details/121508973
上一篇 下一篇

猜你喜欢

热点阅读