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

thank you

Thank you for the info