Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

(How) can I normalize the HSV's v value to be between 0 and 1 with the help of opencv and python?

As I want to categorize and compare photos in terms of their brightness, I want to normalize the V values (HSV) to be between 0 and 1 – with 1 being the brightest. I use opencv with python. Thank you in advance!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import cv2
import numpy as np

# Read an image
frame = cv2.imread("Path/to/img")
# Convert it to hsv
hsv = cv2.cvtColor(frame, cv.COLOR_BGR2HSV)
# Get the V channel
v=hsv[:,:,2]
# Convert it to float
v=v.astype(np.float32)
# Normalize to brightest value
v/=np.amax(v)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading