How do I detect if the image is dark or bright?

I want to make my app can changes it's themes by choosing image. I also want to make it can change the color of user interface components text, hint, and background to change depends in the brightness of the image chosen. How do I do the second one?

maybe this extension helps;
Colors Extractor : Extract colors from image - Extensions - MIT App Inventor Community

To detect if an image is dark or bright, calculate the average pixel intensity. If working with RGB, convert the image to grayscale and find the mean brightness value:

  • Low average intensity → Dark image
  • High average intensity → Bright image

A threshold (e.g., 128 on a scale of 0-255) helps determine brightness. For automation, use tools like OpenCV or PIL in Python

thank you

Thank you for the info