Python, OpenCV: Increasing image brightness without overflowing UINT8 array

前端 未结 5 2170
花落未央
花落未央 2020-12-03 18:42

I am trying to increase brightness of a grayscale image. cv2.imread() returns a numpy array. I am adding integer value to every element of the array. Theoretica

5条回答
  •  误落风尘
    2020-12-03 19:23

    Here is another alternative:

    # convert data type
    gray = gray.astype('float32')
    
    # shift pixel intensity by a constant
    intensity_shift = 50
    gray += intensity_shift
    
    # another option is to use a factor value > 1:
    # gray *= factor_intensity
    
    # clip pixel intensity to be in range [0, 255]
    gray = np.clip(gray, 0, 255)
    
    # change type back to 'uint8'
    gray = gray.astype('uint8)
    

提交回复
热议问题