from PIL import Image
import numpy as np

im = np.array(Image.open('C:\\Users\\LT\\Desktop\\img\\01.jpg'))
print(im.shape,im.dtype)

>>(1080, 1920, 3) uint8

im

>>

array([[[ 4,  1,  0],
        [17, 14,  0],
        [ 4,  1,  0],
        ...,
        [15,  0,  0],
        [15,  0,  0],
        [18,  0,  0]],

       [[ 6,  0,  0],
        [39, 33, 17],
        [36, 30, 16],
        ...,
        [89, 73, 60],
        [82, 64, 50],
        [73, 54, 40]],

       [[ 9,  2,  0],
        [53, 46, 30],
        [54, 46, 33],
        ...,
        [93, 76, 66],
        [78, 60, 50],
        [57, 37, 26]],

       ...,

以上代码可以看出 图像转化为三维数组后,维度分别为宽度,长度,和RGB值;

b = [255,255,255] - im
new_im = Image.fromarray(b.astype('uint8'))
new_im.save('C:\\Users\\LT\\Desktop\\img\\02.jpg')

以上为数组运算,运算完成后转为新图片;利用pillow库的图像变换

 

利用pillow库的图像变换
02jpg

相关文章:

  • 2022-02-02
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-06-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-01-14
  • 2021-12-30
  • 2022-12-23
相关资源
相似解决方案