Hey, I’am beginner

I generate matrix with a python script like :

[[10011]

[01101]

[10000]

[22302]

[44444]]

(The matrix will be animated in a second time)

I would like generate a image from this matrix

Where for exemple :

0 is white

1 is red

2 is yellow

3 is bleu

4 is green

What will be the process to do this work ?

- DAT(table) to CHOP to TOP ?
- Maybe directly in python with the opposite way of sample, like set value (r,g,b,a) of each pixel ?

Hey there,

If you want to do this using the matrix you have written down, you will need to create a color coding for each number. Most comfortable ways is to use a Python dictionary for the conversion. Further on, you can create tables with rgb values for each pixel row, and use a DatTo chop to convert the channels furtherinto TOPs. Find an example attached with a possible approach using just python and standard TD objects.

Best,

Darien

PS: I noticed that with this approach colors were at first inverted, didn’t pay much attention to the order , so you need to evaluate the matrix in reverse order to have it as in your example, that’s why this line of code, in case you wonder:

```
for i, m in enumerate(reversed(matrix), 1):
```

MatrixToColor.tox (1.3 KB)

hey

Everything works very well.

What will be the best way, if the size of my matrix is [128,128]?

I can manually duplicate the nodes “conversion [x]” from 1 to 128.

But for my curiosity, with matices of [1024,1024], (TD will be very slow), but how?

best,

Jeff

HI Jeff,

Yes, the first example I sent will not scale up to very large sizes. It was meant to illustrate how you could tackle this issue. If you understand the principle in that first example, then the generalized solution with that approach would not be hard to infer. Find attached a generalized solution. Change the “n” variable in the controls panel and click “Generate” to generate a table of n by n dimensions i.e (1024x1024). I’m using random data but you can just plug your data there.

Best,

Darien

MatrixToColorGeneralized.tox (1.6 KB)

Hi Darien,

So light and extremely effective.