简体   繁体   English

是否可以使用python中的opencv将图像中的亮度调整为更暗?

[英]Is that possible to adjust the brightness to be more darkest in the image using opencv in python?

Is that possible to reduce the brightness area and i want the result like below是否可以减少亮度区域,我想要如下结果在此处输入图片说明

This is the part that i want the brightness area to become with这是我希望亮度区域成为的部分
在此处输入图片说明

You can change the brightness of the whole picture but I'm not sure how to make a part of it.您可以更改整个图片的亮度,但我不确定如何制作它的一部分。 I think this link helps you. 我认为这个链接可以帮助你。

  1. Determine the brightness region in your image.确定图像中的亮度区域。 My solution is that I counted each pixel(channel value > 100) in each column and decided a reference number.我的解决方案是计算每列中的每个像素(通道值 > 100)并确定一个参考编号。 If the number is bigger than the reference(I chose 55), I considered columns is close to bright(255).如果数字大于参考(我选择了 55),我认为列接近明亮(255)。
  2. After first step, the brightness area is clear so just crop that area.第一步后,亮度区域清晰,因此只需裁剪该区域。
  3. Decrease the brightness of the area.降低该区域的亮度。 Helpful link is here to decrease brightness.有用的链接在这里可以降低亮度。
  4. After decreasing the brightness just replace it with the original part in the source image.降低亮度后,只需将其替换为源图像中的原始部分。

Here is the solution for first step and result.这是第一步和结果的解决方案。

import cv2

img=cv2.imread("/ur/source/image/bright.png")
height, width, channels = img.shape

thresh = [100,100,100]
white = [255,255,255]
white_counter = 0

for x in range(0,width):
    for y in range(0,height):
        channels_xy = img[y,x]
        if all(channels_xy >= thresh):    
            white_counter += 1

    if(white_counter>55):
        for k in range(0,height): 
            img[k,x] = white

    white_counter = 0

cv2.imshow('Result',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Result:结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM