0

I want to ask the more experienced people how to get the RGB values of a pixel in an image using oiio's python bindings.

I have only just begun using oiio and am unfamiliar with the library as well as image manipulation on code level.

I poked around the documentation and I don't quite understand how the parameters work. It doesn't seem to work the same as python and I'm having a hard time trying to figure out, as I don't know C.

A) What command to even use to get pixel information (seems like get_pixel could work)

and

B) How to get it to work. I'm not understanding the parameters requirements exactly.

Edit:

I'm trying to convert the C example of visiting all pixels to get an average color in the documentation into something pythonic, but am getting nowhere.

Would appreciate any help, thank you.

Edit: adding the code

buffer = oiio.ImageBuf('image.tif')

array = buffer.read(0, 0, True)

print buffer.get_pixels(array)

the error message I get is:

# Error: Python argument types in
#     ImageBuf.get_pixels(ImageBuf, bool)
# did not match C++ signature:
#     get_pixels(class OpenImageIO::v1_5::ImageBuf, enum OpenImageIO::v1_5::TypeDesc::BASETYPE)
#     get_pixels(class OpenImageIO::v1_5::ImageBuf, enum OpenImageIO::v1_5::TypeDesc::BASETYPE, struct OpenImageIO::v1_5::ROI)
#     get_pixels(class OpenImageIO::v1_5::ImageBuf, struct OpenImageIO::v1_5::TypeDesc)
#     get_pixels(class OpenImageIO::v1_5::ImageBuf, struct OpenImageIO::v1_5::TypeDesc, struct OpenImageIO::v1_5::ROI)
XJZeng
  • 13
  • 5
  • If you're in Maya, what about using Qt? – Green Cell Oct 23 '19 at 02:31
  • It could help to show us your code. Basically you can either load the pixles into your own float array, or you can use the ImageBuf() to define a image buffer and then use the imagebuf read function to convert all pixles to float and finally use the get_pixel() function. – haggi krey Oct 23 '19 at 08:01
  • please give us component of what you already tried. Also you could also use PIL in maya : https://python-pillow.org/ – DrWeeny Oct 23 '19 at 13:56
  • Hey, thanks for answering! I haven't gotten very far at all with the code to be honest, but if you think it helps, I've added the code block above. I'm also locked into using oiio, because of pipeline. – XJZeng Oct 23 '19 at 16:49
  • The ImageBuf.get_pixels function does not take a true/false value, which is what ImageBuf.read will return. I would recommend reading the documentation, which fully explains this as well as has lots and lots of example code, including doing the exact thing you are asking: https://openimageio.readthedocs.io – Larry Gritz Oct 23 '19 at 16:59

1 Answers1

1

OpenImageIO has several classes for dealing with images, with different levels of abstraction. Assuming that you are interested in the ImageBuf class, I think the simplest way to access individual pixels from Python (with OpenImageIO 2.x) would look like this:

import OpenImageIO as oiio
buf = ImageBuf ("foo.jpg")
p = buf.getpixel (50, 50)   # x, y
print (p)

p will be a numpy array, so the this will produce output like

(0.01148223876953125, 0.0030574798583984375, 0.0180511474609375)
Larry Gritz
  • 13,331
  • 5
  • 42
  • 42
  • Hey Larry, thanks for replying! I feel like I have summoned the eye of Sauron. I've actually tried that before but I only got a () as print out. But since you pointed it out as a solution, I revisited it, and it turns out the reason is '/' vs '\' for the file pathing I'm actually an artist, not a coder. Thanks for your patience! – XJZeng Oct 23 '19 at 17:37