Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Python matrix to TOP

Still a little green? Ask your beginner's questions here

Python matrix to TOP

Postby jeffazzo » Thu Oct 11, 2018 5:42 am

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 ?
Attachments
DEST.png
DEST.png (16.16 KiB) Viewed 229 times
jeffazzo
 
Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

Re: python DAT to TOP

Postby Qvoloid » Thu Oct 11, 2018 6:53 am

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:
Code: Select all
for i, m in enumerate(reversed(matrix), 1):
Attachments
MatrixToColor.tox
Conversion to texture from matrix
(1.3 KiB) Downloaded 3 times
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid
 
Posts: 53
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

Re: Python matrix to TOP

Postby jeffazzo » Thu Oct 11, 2018 10:59 am

Really, thank you

I will study all that :geek:
jeffazzo
 
Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

Re: Python matrix to TOP

Postby jeffazzo » Thu Oct 11, 2018 6:17 pm

hey

Everything works very well. :D

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
jeffazzo
 
Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

Re: Python matrix to TOP

Postby Qvoloid » Fri Oct 12, 2018 4:32 am

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
Attachments
MatrixToColorGeneralized.tox
Generalized solution
(1.6 KiB) Downloaded 9 times
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid
 
Posts: 53
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

Re: Python matrix to TOP

Postby jeffazzo » Fri Oct 12, 2018 7:46 am

Hi Darien,
So light and extremely effective.
jeffazzo
 
Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm


Return to Beginners

Who is online

Users browsing this forum: Google [Bot] and 13 guests