0

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)
DrBwts
  • 3,470
  • 6
  • 38
  • 62
coderAI
  • 1
  • 1
  • Just to explain the "too dark" effect: `cv2.imread` returns `np.uint8` arrays when reading jpg files. When you add those up using `sum`, this will overflow the 8 bit value range. So for a white pixel (value 255 in the V channel) in all 3 images, the sum becomes (255 + 255 + 255) % 256 = 253, not 765 as expected. – Jeronimo Jul 29 '22 at 11:56
  • thank you very much , I resolved the dark issue by converting my V array to a float it's memory consuming but at least it works. – coderAI Jul 29 '22 at 13:51

0 Answers0