Top Save Temp File

It would be nice if we could save images from tops (and other ops maybe also) as a temp file an return the byteData directly from the function. This way, we would not need to go the route of:

save image
open image
read image
close image
delete image

If you’re looking to get the raw uncompressed data bytes, have you looked into TOP to CHOP?
It will convert a TOP image into an array of CHOP Channels.

Similarly you can use TOP.numpyArray(), or even CHOP.numpyArray() and Channel.numpyArray() in a python script to get the sample values.

If you’re looking to get the encoded data bytes (jpeg format etc), then perhaps you might use an external python library to compress the above arrays into the format you require.


Don’t want to piggyback on this thread, but if I understand correctly we can convert TOP->numpy or CHOP-> numpy with the helper functions, but right now there’s no way to go numpy->TOP or numpy->CHOP efficiently, is there? Maybe with the introduction of the Buffer Select TOP you could grab buffers from a c++ chop that has Boost or pybind11 bindings to numpy, but that feels like it would introduce a lot of overhead. Am I missing something simple here? (Other than saving and reloading from disk, which was the primary issue of the initial post).

Well, it would be nice if I do not need to do that :slight_smile:
This is not a current issue, but im diving deeper into the whole WebServerDAT business, and to send image data from inside of TD it would be nice to not go the way arround saving it.

We currently do not have a way of efficiently moving numpy array data back into TOPs but
if you’re looking to avoid temporary disk files, you can do it if you install the pillow library in 10k.

I had a parallel copy of python 3.5 installed, and used the pip utility to install pillow.

from PIL import Image
import io
import numpy

n = op('moviefilein1')

#convert from float-32 to 8-bit RGBA
rgbA = op('moviefilein1').numpyArray()*255
rgbA = rgbA[:,:,:-1] #strip off alpha
rgbA = rgbA.astype(numpy.uint8)
im = Image.fromarray(rgbA, mode='RGB')

#save into memory buffer
fio = io.BytesIO(), 'JPEG')

#rewind and grab data
d =

#save to disk to verify, but otherwise bytes are ready ..
#f = open('test1.jpeg', 'wb')

Upcoming builds of 2019.30000 will have a new saveByteArray() method available in TOPs that will save/compress a TOPs contents into a Python bytearray object, with the specified file format (.jpg, .tiff, .exr etc.). This will greatly improve this workflow.

1 Like

Thanks alot for taking care of that. I tried it with exp2019.33840 but got an error that saveByteArray() is not a member of top.
Also, just wondering how one would go about using a specific algorythm.