Skip to content

Width and height inversion in otbObject.shape

When trying to reproduce "Interactions with numpy" example from the README (with a non-square image) :

ValueError                                Traceback (most recent call last)
Input In [15], in <cell line: 5>()
      2 white_noise = np.random.normal(0, 50, size=inp.shape)  # this is a numpy object
      4 # Adding the noise to the image
----> 5 noisy_image = inp + white_noise  # magic: this is a pyotb object that has the same georeference as input.
      6                                  # `np.add(inp, white_noise)` would have worked the same
      7 noisy_image.write('image_plus_noise.tif')

File ~/Projets/git/pyotb/pyotb/core.py:535, in otbObject.__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
    532         return NotImplemented
    534 # Performing the numpy operation
--> 535 result_array = ufunc(*arrays, **kwargs)
    536 result_dic = image_dic
    537 result_dic['array'] = result_array

ValueError: operands could not be broadcast together with shapes (10800,21600,1) (21600,10800,1)

It is working with the image in tests/Data dir, but this one does not have a projection.
Trying with a normal projected image results in the above error.

EDIT : one other failure I had was due to bad inputs.

Edited by Cresson Remi