简体   繁体   中英

Change the hsv value of an image in python

I have an image which is converted to HSV using opencv.

I want to conver the overall V value in HSV to 200, is there anyway.

I used the following code to convert the image to hsv and split into h,s,v

image = cv2.imread('../images/test/image_1.jpg',cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image)

image = cv2.merge([h,s,v])
out = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
cv2.imshow('image',out)
k = cv2.waitKey(0)
cv2.destroyAllWindows()

All you need is this line.

image[:,:,2] = 200

This changes the V value to 200.

Your final program should look like.

image = cv2.imread('../images/test/image_1.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

image[:,:,2] = 200 # Changes the V value

out = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
cv2.imshow('image',out)
k = cv2.waitKey(0)
cv2.destroyAllWindows()

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.

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