It's just an idea - I don't know if some sort of scripting is possible.
I think it's not so exhausting / error-prone than placint 10,000 numbers manually.
Requirements and conditions:
a) Illustrator & Photoshop
b) In the end the numbers will be rasterized, no more editable text. Is this OK?
c) One square is not just 1 pixel but something like 42 x 42 px or so, like in your picture above.
1. I copy the squares of same color with the help of the wand tool on different layers. We have to know the exact width and height of one colored square and the file has to be precisely 1 hundred times as wide and high.
2. In Illustrator I create an artboard for example 42x100=4200 px wide and high.
3. I modify the grid (Edit > Preferences) matching to the squares.
4. I place a number "1" in the top left and in the top right grid square and blend them with 98 steps --> 100 number "1".
5. I copy this new object exactly 42 px downwards and then hit Strg+D (Windows) for duplicating 98 times. --> 10,000 number "1"!
I group the resulting big number grid.
6. I copy this artboard 6 times, one for each color number.
7. With Find/Replace I change the numbers per artboard. (Hide the other groups in the layer panel!)
8. With File > Place I import each artboard and rasterize it, because the following step doesn't work with smart objects. It's a good idea to rename the layers with matching names.
9. In the layer panel I select the squares of the first color and invert the selection. I activate the layer with the number "1" and hit the delete key. Only the numbers above the gray-1 squares are left over.
10. This I repeat with the following 6 pairs of square and number layers.
That's for a beginning. Someone may come around and has more and/or better ideas.