There is no need to recognise the colours. It would be enough to detect the colour change on the boundary. Here is the script. Inputs might depend on the screen resolution. Default parameters work on my 96dpi display.