将图片中的黄色修改为红色
1 from PIL import ImageDraw,Image 2 img = Image.open(r'C:\Users\87823\Desktop\warning.jfif') 3 draw_obj = ImageDraw.Draw(img) 4 w,h = img.size 5 # 创建图像区域 6 img_output = Image.new('RGB',(2*w,h)) 7 # 将原图复制到(0,0) 8 img_output.paste(img,(0,0)) 9 10 def get_color(): 11 # 将黄色修改为红色 12 # print(oldColor) 13 # 获取每个通道的值 正宗的黄色(255,255,0) 14 if oldColor[0]>60 and oldColor[1]>60: 15 return(oldColor[0],0,oldColor[2]) # 返回红色 16 else: 17 return oldColor 18 19 for x in range(w): 20 for y in range(h): 21 oldColor = img.getpixel((x,y)) 22 draw_obj.point((x,y),fill=get_color()) 23 img_output.paste(img,(w,0)) 24 img_output.show()
正是江南好风景