Calculate the brightness of an image. Given a 3D array representing an RGB image (height x width x 3), compute the average brightness across all pixels using the luminance formula.
import numpy as np
def calculate_brightness(image):
image = np.array(image, dtype=float)
# Luminance formula: 0.299*R + 0.587*G + 0.114*B
luminance = 0.299 * image[:, :, 0] + 0.587 * image[:, :, 1] + 0.114 * image[:, :, 2]
brightness = np.mean(luminance)
return round(float(brightness), 4)