Analyse image

Would it be possible to analyse a jpeg to see what colour or colours are more prominate and use them for further purposes. One implmentation im trying todo is have text go over changing images, keeping the text the same colour leaves problems with readablity with say a black-ish or white-ish backing

Just something that I would like, not entirley sure if its possible or how it could be done.