|
- import numpy as np
- import os
- from PIL import Image
- url = r'G:\BaiduNetdiskDownload\pdf文件\级别 (3)--阅读\3-02 Sniff【有书】'
- for lujing, liebiao, wenjian in os.walk(url):
- for a in wenjian:
- patha = lujing + '\\' + a
- print(patha)
- name=lujing + '\\' + f'修改后{a}'
- print(name)
-
- img = Image.open(patha)
- array = np.array(img)
- rows = len(array)
- cols = len(array[0])
- # 图片尺寸
- print(rows)
- print(cols)
- # 设置图片修改后图片颜色 作者这里设置为白色
- colorl = [255, 0, 255]
- # 依次遍历我们需要修改颜色的图片区域
- for col in range(20, 920):
- for row in range(900, 1060):
- array[row, col] = colorl
- new_img = Image.fromarray(array)
- # new_img.show()
- new_img.save(name)
复制代码
for循环里输入像素即可
|
|