How many permutations of pixels in a square?

267 Views Asked by At

enter image description here

Given a square of dimensions x by y pixels, how many permutations of colors of pixels are there in the square? Assume that each square is 1 pixel and that this square is 5x5 pixels. How many unique ways can this square of pixels be permuted? Also assume that the specific colors shown here don't matter.

2

There are 2 best solutions below

8
On BEST ANSWER

Assume we have $k$ distinct colors and the number of each color is $n_1,\ldots,n_k$. Then the answer is $$\frac{(xy)!}{n_1!n_2!\cdots n_k!}$$ by the elementary combinatorial formula for enumerating permutations.

1
On

If we want to make the question more interesting by allowing pixels with the same colour (i.e. indistinguishable pixels), the general solution can be obtained as follows:

Let $n_c$ be the number of colours and $c_i, i=1..n_c$ be the multiplicities of the colours. Then the total number of permutations is given by $$P = \frac{(xy)!}{\prod_{i=1}^{n_c} c_i!}$$ This is because there are $c_i!$ ways to rearrange the $i$-coloured pixels without changing the image. To get the denominator in a different form, we can use $$d(n):=|\{i | c_i \ge n\}|$$ wich counts how many colours $i$ have at least $n$ pixels coloured by $i$. Then the denominator is $$\prod_{i=1}^{n_c} c_i! = 1\cdot2\cdot \ldots c_1 \cdot 1 \cdot \ldots c_2 \ldots c_{n_c} = 1\cdot 1\cdot \ldots 1 \cdot 2 \cdot \ldots = \prod_{j=1}^{xy} j^{d(j)}$$ The upper limit of the RHS product can be replaced by $\max_{i} c_i \le xy$