I think I pretty much agree with Johnathan: while I have no issue with
the use of NumPy, part of me feels that making it a hard dependency of
the OIIO Python bindings is a step too far (for lack of a better term).
Maybe that's just my fear of change talking though... If pybind11 is
worth the effort (which it sounds like it is), and continuing to support
the native Python types with it is a massive hassle or just plain
infeasible, then I wouldn't put up much of a fight.
I would also agree with the others in preferring the multidimensional
array layout in that case.
-Nathan
On Nov 2, 2017 5:57 AM, "Jonathan Tilden (2K)" <[email protected]
<mailto:[email protected]>> wrote:
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]
<mailto:[email protected]>] *On Behalf Of
*Larry Gritz
*Sent:* Wednesday, November 1, 2017 11:09 AM
*To:* OpenImageIO dev list <[email protected]
<mailto:[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] <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