feature to determine image too dark opencv 1

feature to determine image too dark opencv

blur = cv2.blur(image, (5, 5))  # With kernel size depending upon image size
if cv2.mean(blur) > 127:  # The range for a pixel's value in grayscale is (0-255), 127 lies midway
    return 'light' # (127 - 255) denotes light image
else:
    return 'dark' # (0 - 127) denotes dark image

Here is what the above code is Doing:
1. We are using the cv2.blur() function to blur the image.
2. The cv2.blur() function takes two arguments: the image and the kernel size.
3. The kernel size is a tuple that specifies the width and height of the kernel.
4. The kernel size depends on the size of the image.
5. The cv2.mean() function takes the image as an argument and returns the average pixel value.
6. The average pixel value is a tuple that contains the average of the blue, green, and red pixel values.
7. We are only interested in the average of the blue, green, and red pixel values.
8. The average of the blue, green, and red pixel values is the average pixel value.
9. If the average pixel value is greater than 127, then the image is light.
10. If the average pixel value is less than 127, then the image is dark.

Similar Posts