How to change numpy image?

I have a numpy array image with a shape (channels, height, width), how can I change it so that it has a shape (height, width, channels)?

+4
source share
3 answers

I assume it will be faster to use the numpy built-in function.

np.rollaxis(array_name,0,3).shape
+8
source

You can use transpose()to select the order of the axes. In this case, you want:

array.transpose(1, 2, 0)

This creates a new view in the original array when possible (data will not be copied).

+7
source

You can do:

import numpy as np
newim = np.zeros((height, width, channels))
for x in xrange(channels):
    newim[:,:,x] = im[x,:,:]
0
source

Source: https://habr.com/ru/post/1588968/


All Articles