'Formula for the number of possible image variations given the number of pixels?

It's probably been asked before but I can't find it. Assume you can only use two colors and are given a number of pixels. How many possible image variations are possible? For 1 pixel, it's 2. For 2 pixels, it's 4. For 3 pixels, it's 8. It looks like it's a 2 to the power of however many pixels.

What if you allowed 3 colors or any number of different colors. Is it 3 to the power of however many pixels you work with?

What is the generalization of the formula? Thank you!



Solution 1:[1]

This Question Should Be Posted On The Math Stack-Exchange But Nevertheless Here's How You Solve It.
This Is A Type Of Permutation Problem.
Lets Consider Each Pixel to be a box and the color to be a ball.
First box can store one out of k balls. So No Of Possibilities is k.
Second Box Can Store one out of k balls. So No Of Possibilities is again k.
But No Of Possibilities if both of them take place is k^2
Generalizing It For n Boxes: It Is k^n
Where in your question k is no of color choices and n is no of pixels.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mrtechtroid