What is the correct way to change image channel ordering between channels first and channels last?

后端 未结 5 589
暗喜
暗喜 2021-02-02 07:28

I can not for the life of me figure out how to switch the image ordering. images are read in (x,x,3) format, theano requires it to be in (3,x,x) format. I tried changing the ord

5条回答
  •  走了就别回头了
    2021-02-02 07:52

    I agree with @Qualia 's comment, np.moveaxis(a, source, destination) is easier to understand. This does the job:

    x = np.zeros((12, 12, 3))
    x.shape
    #yields: 
    (12, 12, 3)
    
    x = np.moveaxis(x, -1, 0)
    x.shape
    #yields: 
    (3, 12, 12)
    

提交回复
热议问题