I have this image attached to this description. I want to select a region anywhere on the image and increase its brightness without affecting the other parts of the image. How to handle this situation in python + OpenCV.
The brightness of a region in a black rectangle should be affected by a certain scalar.
Here is one way to do that in Python/OpenCV.
Crop the region. Increase its brightness. Then put the modified region back into the image.
Input:
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()
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.