colour-science / colour

Colour Science for Python
https://www.colour-science.org
BSD 3-Clause "New" or "Revised" License
2.13k stars 263 forks source link

[BUG]: read_image failing due to incorrect signature for OIIO read_image #1252

Closed n-garc closed 1 month ago

n-garc commented 8 months ago

Description

When attempting to read an image with read_image(path), I am getting an incorrect signature error from OpenImageIO (v2.5.9). The error seems to be originating from colour/io/image.py:278. The signature was changed in 2.1.19.0 in response to this bug report AcademySoftwareFoundation/OpenImageIO/issues/2676.

Code for Reproduction

path = '/home/user/src_dir/test_images/image1.jpeg'
image1 = colour.read_image(path)

Exception Message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[14], line 2
      1 path = '/home/user/src_dir/test_images/image1.jpeg'
----> 2 image1 = colour.read_image(path)

File ~/anaconda3/envs/pixelsorting/lib/python3.12/site-packages/colour/io/image.py:444, in read_image(path, bit_depth, method, **kwargs)
    441 if method == "openimageio":  # pragma: no cover
    442     kwargs = filter_kwargs(function, **kwargs)
--> 444 return function(path, bit_depth, **kwargs)

File ~/anaconda3/envs/pixelsorting/lib/python3.12/site-packages/colour/utilities/common.py:1086, in required.<locals>.wrapper.<locals>.wrapped(*args, **kwargs)
   1083 for requirement in requirements:
   1084     _REQUIREMENTS_TO_CALLABLE[requirement](raise_exception=True)
-> 1086 return function(*args, **kwargs)

File ~/anaconda3/envs/pixelsorting/lib/python3.12/site-packages/colour/io/image.py:278, in read_image_OpenImageIO(path, bit_depth, attributes)
    270 specification = image_input.spec()
    272 shape = (
    273     specification.height,
    274     specification.width,
    275     specification.nchannels,
    276 )
--> 278 image = image_input.read_image(bit_depth_specification.openimageio)
    279 image_input.close()
    281 image = np.array(image, dtype=bit_depth_specification.numpy).reshape(shape)

TypeError: read_image(): incompatible function arguments. The following argument types are supported:
    1. (self: OpenImageIO.OpenImageIO.ImageInput, subimage: int, miplevel: int, chbegin: int, chend: int, format: OpenImageIO.OpenImageIO.TypeDesc = <TypeDesc 'float'>) -> object
    2. (self: OpenImageIO.OpenImageIO.ImageInput, chbegin: int, chend: int, format: OpenImageIO.OpenImageIO.TypeDesc = <TypeDesc 'float'>) -> object
    3. (self: OpenImageIO.OpenImageIO.ImageInput, format: OpenImageIO.OpenImageIO.TypeDesc = <TypeDesc 'float'>) -> object

Invoked with: <OpenImageIO.OpenImageIO.ImageInput object at 0x7fde68d9bcb0>, None

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.12.2 | packaged by conda-forge | (main, Feb 16 2024,       *
*   20:50:58) [GCC 12.3.0]                                                    *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.4                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.34.0                                                      *
*       matplotlib : 3.8.3                                                    *
*       numpy : 1.26.4                                                        *
*       scipy : 1.12.0                                                        *
*       tqdm : 4.66.2                                                         *
*       trimesh : 4.2.0                                                       *
*       OpenImageIO : 2.5.9.0                                                 *
*       xxhash : 3.4.1                                                        *
*                                                                             *
===============================================================================

defaultdict(dict,
            {'Interpreter': {'python': '3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]'},
             'colour-science.org': {'colour': '0.4.4'},
             'Runtime': {'imageio': '2.34.0',
              'matplotlib': '3.8.3',
              'numpy': '1.26.4',
              'scipy': '1.12.0',
              'tqdm': '4.66.2',
              'trimesh': '4.2.0',
              'OpenImageIO': '2.5.9.0',
              'xxhash': '3.4.1'}})
KelSolaar commented 8 months ago

Hi @n-garc,

This one is odd because our tests pass with OIIO on Github with whatever latest is available. I tried with 2.5.6.0 and it is all good too whilst being much more recent than 2.1.19.0. I tried both EXR and JPG files.

Cheers,

Thomas

KelSolaar commented 1 month ago

Closing this one as non-reproducible.