Automatic image grid overlaying in Python