I Am trying to homogenise a set of images to have the same brightness so I transformed my images into HSV images and I modified the value of the V channel , i used the avrege value of each 3 successive images and then replaced the V value of a specific image with that value, but for some reason the images where too dark. is there a way to homogenise the images using the V channel and how could I fix the images brightness problem.
here is the code that i used :
def imgChange(imgPath):
img = cv2.imread(imgPath)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v= cv2.split(hsv)
return v
def changeV(imgPath, vNew):
print(imgPath)
img = cv2.imread(imgPath)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v= cv2.split(hsv)
hsv = cv2.merge((h, s, vNew))
img = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imwrite(imgPath, img)
V = []
a = []
for i, image in enumerate(os.listdir(pathDossier)) :
if image.endswith(".jpg"):
pathimg = pathDossier + "\\" + image
a = imgChange(pathimg)
V.append(imgChange(pathimg))
for i, image in enumerate(os.listdir(pathDossier)) :
if image.endswith(".jpg"):
if i < len(V)-3 :
listdata = (sum(V[i:i+3]))//3
vNew = np.array(listdata, dtype = np.uint8)
pathimg = pathDossier + "\\" + image
changeV(pathimg, vNew)