How to check if the image is HWC or CHW?
Use below code to get each channel's array
from PIL import Image
import numpy as np
from skimage import io
import cv2
import scipy.misc
png_file = './Screenshot.png'
# PIL
print('==========PIL==========')
img = Image.open(png_file)
print(img)
arr = np.array(img)
print(arr)
# check if the image is HWC, if yes, the arr0/1/2 can show correctly
arr0 = arr[:,:,0]
arr1 = arr[:,:,1]
arr2 = arr[:,:,2]
arr_wrong = arr[0,:,:]
print(arr0)
print(arr1)
print(arr2)
print(arr_wrong)
scipy.misc.imsave('0.png',arr0)
scipy.misc.imsave('1.png',arr1)
scipy.misc.imsave('2.png',arr2)
scipy.misc.imsave('wrong.png',arr_wrong)
浙公网安备 33010602011771号