0%
Theme NexT works best with JavaScript enabled
PIL
1 2 3 4 5 6 7 8 9 10 11 from PIL import Imageimport numpy as npimg = Image.open ("1.jpg" ) img.load() array = np.asarrary(img) img.show() img.save("./new_img.jpg" )
PIL.Image包有很多其他的功能,比如:
1 2 Image.fromarray(data,'RGB' )
cv2
1 2 3 4 5 6 import cv2img = cv2.imread("./1.jpg" ) grey_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) rgb_img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
cv2
一个有用的method是resize
1 img = cv2.resize(raw_img,(width,height))
tensorflow
1 2 3 4 5 6 7 8 9 import tensorflow as tfimg = tf.keras.preprocessing.image.load_img("./i.jpg" ,target_size=(32 ,32 ,3 )) img = tf.keras.preprocessing.image.img_to_array(img) img = tf.keras.preprocessing.image.array_to_img(array) tf.keras.utils.save_img(path,array)