I am working with the Script TOP and am trying to access a 3D texture created by stacking multiple images. Specifically, I would like to retrieve a numpy array with the shape (N, res_x, res_y, 3), where N represents the number of images, and res_x and res_y are the dimensions of each image with 3 RGB channels.
Currently, I am using an OP Viewer to flatten the images and then extracting the data in Python inside the Script TOP. However, this method is quite inefficient in terms of performance.
Is it possible to use the numpyArray() method to directly access such a 3D texture from the Script TOP? If so, I would appreciate any guidance or examples on how to achieve this.
I had a similar use case recently. My approach was to use a GLSL top to extract one slice of the 3d texture at a time. I parametrized the depth of the slice, then wrote a script that loops through the depth values, and for each one appends the result of op.numpyArray() to a larger w x h x d x 4 array. Not sure if the performance is any better than flattening with opViewer and dividing into patches, but this should get around resolution limits for those using the non-commercial version, if I understand correctly.
In addition to reading from 3d textures to a numpy array, it would also be great if we could write to 3d textures from an array with copyNumpyArray()!
This is a simple demo of the “slice” approach outlined above. Including a simple handy tox for selecting a u, v, or w slice from a 3d texture by normalized parameter.
Hey,
just tuning it here. The current version of T3D includes a toTOPT3D, which basically converts a 3D texture to either on slice of it or a flattended version of the whole thing. Not sure if that’s what you’re looking for.