你的喜欢代码

import numpy as np

import matplotlib.pyplot as plt

import cv2

 

def log(c, img):

    output = c * np.log(1.0 + img)

    output = np.uint8(output + 0.5)

    return output

 

img = cv2.imread('./night.jpg')

img2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

 

plt.imshow(img2)

plt.show()

 

output = log(33, img)

output2 = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)

plt.imshow(output2)

plt.show()

grayHist = calcGrayHist(output)

x = np.arange(256)

plt.plot(x, grayHist, 'r', linewidth=2, c='black')

plt.xlabel("gray Label")

plt.ylabel("number of pixels")

plt.show()

 

out = 2.00 * output

out[out > 255] = 255

# 数据类型转换

out = np.around(out)

out = out.astype(np.uint8)

out2 = cv2.cvtColor(out, cv2.COLOR_BGR2RGB)

plt.imshow(out2)

plt.show()

def calcGrayHist(I):

    # 计算灰度直方图

    h, w = I.shape[:2]

    grayHist = np.zeros([256], np.uint64)

    for i in range(h):

        for j in range(w):

            grayHist[I[i][j]] += 1

    return grayHist

 

grayHist = calcGrayHist(out)

x = np.arange(0, 256, 2)

y = [grayHist[i] for i in range(len(grayHist)) if i % 2 == 0]

 

plt.plot(x, y, 'r', linewidth=2, c='black')

plt.xlabel("gray Label")

plt.ylabel("number of pixels")

plt.show()

 

 

import cv2

import numpy as np

 

#通道分解

(b,g,r) = cv2.split(out) 

bH = cv2.equalizeHist(b)

gH = cv2.equalizeHist(g)

rH = cv2.equalizeHist(r)

result = cv2.merge((bH,gH,rH),)#通道合成

 

# 并排放置原图和效果图

res = np.hstack((out,result))

res2 = cv2.cvtColor(res, cv2.COLOR_BGR2RGB)

plt.imshow(res2)

plt.show()

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值