On one hand, I'm not a huge fan of having the python bindings depend on another
library (even though we use numpy extensively). I rather like that its self
contained once all compiled.
Using the older python arrays, you can simply do the following to efficiently
get it into a numpy array:
pixels = np.frombuffer(imginput.read_image(0, 3, oiio.FLOAT), dtype='f')
Similarly you can convert it back into a regular array to imageout with the
following:
pixels.astype('f', copy=False).data
On the other hand, it would be convenient to not have to read pixels through a
wrapper function, but directly in the API. If that were the route, I would
prefer the multidimensional array.
My 2 cents,
-J
From: Oiio-dev [mailto:[email protected]] On Behalf Of
Larry Gritz
Sent: Wednesday, November 1, 2017 11:09 AM
To: OpenImageIO dev list <[email protected]>
Subject: [Oiio-dev] Python bindings question
Last weekend I started to tinker with pybind11
(https://github.com/pybind/pybind11<https://github.com/pybind/pybind11>), which
is very similar to Boost.Python, but header-only, allegedly builds MUCH faster,
and by starting with C++11 as a baseline, its use and implementation are a lot
simpler.
I got partially done with converting the oiio python bindings to it, and am
liking the direction it was going, so I'll probably finish it. But an issue has
come up that I'm seeking feedback on.
For actual blocks of pixels, like the results of ImageInput.read_image(), it
seems that it's a lot more straightforward to pass back and forth NumPy arrays
rather than old style python arrays. So...
1. Does anybody object to that? Is NumPy already deep enough in your Python
practice that you would accept (and maybe prefer) switching to directly using
numpy arrays to pass image data around?
2. If so, would you prefer that it hand you a true multidimensional array
organized like [y][x][channel]? Or would you rather just get a flat 1D array
with all the values, and you can cast it to the array shape that you prefer?
--
Larry Gritz
[email protected]<mailto:[email protected]>
_______________________________________________
Oiio-dev mailing list
[email protected]<mailto:[email protected]>
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org<http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org