I think there are some potentially useful ideas in this answer, but I've not stumbled on the solution yet.