//***********************安装库***********************//
pip install pillow //安装Pillow库,Image类是Pillow库中的类
pip install numpy //安装numpy库,numpy是数值计算扩展库
pip install matplotlib
import numpy as np
from PIL import Image
img1 = Image.open('./001.jpg')
img1.show()
arr_img1 = np.array(img1)
print(type(arr_img1))
print(arr_img1.shape)
print(arr_img1)
for i in range(100,110):
for j in range(100,150):
arr_img1[i][j][0] = 255
arr_img1[i][j][1] = 0
arr_img1[i][j][2] = 0
for i in range(200,210):
for j in range(200,250):
arr_img1[i][j][0] = 255
arr_img1[i][j][1] = 255
arr_img1[i][j][2] = 0
for i in range(300,310):
for j in range(300,350):
arr_img1[i][j][0] = 0
arr_img1[i][j][1] = 0
arr_img1[i][j][2] = 255
arr_img1 = arr_img1.astype(np.uint8)
print(type(arr_img1))
img2 = Image.fromarray(arr_img1)
img2.show()
import numpy as np
from PIL import Image
arr_img2 = np.zeros((300,300,3))
for i in range(100):
for j in range(300):
arr_img2[i][j][0] = 255
arr_img2[i][j][1] = 0
arr_img2[i][j][2] = 0
for i in range(100,200):
for j in range(300):
arr_img2[i][j][0] = 255
arr_img2[i][j][1] = 255
arr_img2[i][j][2] = 0
for i in range(200,300):
for j in range(300):
arr_img2[i][j][0] = 0
arr_img2[i][j][1] = 0
arr_img2[i][j][2] = 255
arr_img2 = arr_img2.astype(np.uint8)
img2 = Image.fromarray(arr_img2)
img2.show()
import numpy as np
from PIL import Image
from PIL import ImageFilter
img1 = Image.open('./001.jpg').convert('L')
img1.show()
region = (100,100,600,400)
img2 = img1.crop(region)
img2.show()
img3 = img2.rotate(180)
img3.show()
img4 = img3.filter(ImageFilter.CONTOUR)
img4.show()
import numpy as np
from PIL import Image
from PIL import ImageFilter
img1 = Image.open('./001.jpg')
img2 = img1.filter(ImageFilter.FIND_EDGES)
img2.show()
img3 = img1.filter(ImageFilter.EMBOSS)
img3.show()
import numpy as np
from PIL import Image
from PIL import ImageFilter
from pylab import *
img1 = Image.open('./001.jpg')
imshow(img1)
x = [200,200,500,500,200]
y = [100,400,400,100,100]
plot(x[:4],y[:4],'r*')
plot(x[:5],y[:5],'y--')
title("001.jpg")
show()