An invariant measure of disorder in patterns