Traceback Error
Traceback (most recent call last):
File "C:\Users\trial2\trial.py", line 55, in <module>
image_stack(image)
File "C:\Users\trial2\trial.py", line 41, in image_stack
transposed_axes = np.transpose(img, axes=concat)
File "<__array_function__ internals>", line 5, in transpose
File "C:\Users\trial2\venv\lib\site-packages\numpy\core\fromnumeric.py", line 660, in transpose
return _wrapfunc(a, 'transpose', axes)
File "C:\Users\trial2\venv\lib\site-packages\numpy\core\fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
ValueError: axes don't match array
The Traceback Error is also there, if that helps to solve the issue I need to calculate the new transpose axes for the image that has been inputted into the function as parameter. The function gets the shape of the image, and then calculates the transpose axes for the image. The problem is occurring in transposing the image array to the new axes. I can't figure out the issue to why it isn't working. Do I need to turn the concat variable into a tuple for it to work properly or is something else causing the issue for it
def image_stack(image):
img_shape = cv2.imread(image).shape
img = np.asarray(img_shape)
print(type(img))
n = len(img)
val_1 = list(range(1, n - 1, 2))
val_2 = list(range(0, n - 1, 2))
print(img)
if n % 2 == 0:
y_ax = val_1
x_ax = val_2
axes = (y_ax, x_ax, [n-1])
else:
y_ax = val_2
x_ax = val_1
axes = (y_ax, x_ax, [n - 1])
print(type(axes))
concat = np.concatenate(axes)
print(concat)
if type(axes) == tuple:
transposed_axes = np.transpose(img, axes=concat)
print(transposed_axes)
image = 'C:\\trial_images\\9.jpg'
image_stack(image)
img.shape
andconcat
value. For a 2d array,axes
an only be[0,1]
(no change) or [1,0]` (default).. For 3d it has to be some permutation of [0,1,2]. If your
concat` isn't something like that, I suggest rereadingtranspose
docs. – Adebayoimg.shape
was [720, 1280, 3 ] and forconcat
the values where [0,1, 2] by the type wasnumpy.ndarray
. Should I change it to a tuple, or are the values incorrect as you said [0,1,2] are a permutation for 3d – Prismatic