繁体   English   中英

如何使用python在opencv中通过某个标量影响某个区域的亮度?

[英]How to affect a certain region's brightness by a certain scalar in opencv with python?

我在此描述中附上了这张图片。 我想在图像的任何位置选择一个区域并增加其亮度而不影响图像的其他部分。 如何在python + OpenCV中处理这种情况。

黑色矩形中某个区域的亮度应该受某个标量的影响。

任何的想法。 输入图像 输出图像

这是在 Python/OpenCV 中执行此操作的一种方法。

裁剪区域。 增加它的亮度。 然后将修改后的区域放回图像中。

输入:

在此处输入图片说明

import cv2
import numpy as np

# load image
img = cv2.imread('orange_flower.jpg')

# specify region
x,y,w,h = 480,183,163,115

# crop region
crop = img[y:y+h, x:x+w]

# increase brightness of crop
gain = 1.5
crop = (gain * crop.astype(np.float64)).clip(0,255).astype(np.uint8)

# put crop back into input
result = img.copy()
result[y:y+h, x:x+w] = crop

# save output
cv2.imwrite('orange_flower_result.jpg', result)

# Display various images to see the steps
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果:

在此处输入图片说明

暂无
暂无

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

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