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)
4

1 回答 1

1

OpenImageIO 有几个用于处理图像的类,具有不同的抽象级别。假设您对该ImageBuf课程感兴趣,我认为从 Python(使用 OpenImageIO 2.x)访问单个像素的最简单方法如下所示:

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

p 将是一个 numpy 数组,因此这将产生类似的输出

(0.01148223876953125, 0.0030574798583984375, 0.0180511474609375)
于 2019-10-23T16:56:08.267 回答