Python3实现取图片 * 定的像素替换指定的颜色示例
作者:徐为波 时间:2022-08-31 15:33:21
本文实例讲述了Python3实现取图片 * 定的像素替换指定的颜色。分享给大家供大家参考,具体如下:
1、原始图片
2、修改脚本:
# -*- coding:utf-8 -*-
#! python3
from PIL import Image
i = 1
j = 1
img = Image.open("e:/pic/222.jpg")#读取系统的内照片
print (img.size)#打印图片大小
print (img.getpixel((4,4)))
width = img.size[0]#长度
height = img.size[1]#宽度
for i in range(0,width):#遍历所有长度的点
for j in range(0,height):#遍历所有宽度的点
data = (img.getpixel((i,j)))#打印该图片的所有点
print (data)#打印每个像素点的颜色RGBA的值(r,g,b,alpha)
print (data[0])#打印RGBA的r值
if (data[0]>=170 and data[1]>=170 and data[2]>=170):#RGBA的r值大于170,并且g值大于170,并且b值大于170
img.putpixel((i,j),(234,53,57,255))#则这些像素点的颜色改成大红色
img = img.convert("RGB")#把图片强制转成RGB
img.save("e:/pic/testee1.jpg")#保存修改像素点后的图片
3、运行脚本:
4、图片变化成
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/xwbk12/article/details/78998196
标签:Python3,图片,替换,颜色
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python自动安装pip
2021-04-06 09:30:00
对Python 字典元素进行删除的方法
2021-07-03 00:27:50
超详细的Python安装第三方库常用方法汇总
2023-08-26 08:54:47
![](https://img.aspxhome.com/file/2023/7/91917_0s.png)
python遗传算法之单/多目标规划问题
2021-09-09 20:27:24
![](https://img.aspxhome.com/file/2023/8/76878_0s.png)
使用Python编写简单网络爬虫抓取视频下载资源
2023-11-02 01:44:22
![](https://img.aspxhome.com/file/2023/4/89154_0s.gif)
编写安全的SQL Server扩展存储过程
2008-11-25 11:16:00
Python编程tkinter库Canvas实现涂鸦颜色表及围棋盘示例
2023-08-02 13:21:02
![](https://img.aspxhome.com/file/2023/3/92073_0s.png)
Javascript中数组方法汇总(推荐)
2023-07-16 08:33:02
Python脚本实现自动发带图的微博
2021-04-18 08:37:01
![](https://img.aspxhome.com/file/2023/4/100264_0s.png)
一文深入了解Python中的继承知识点
2023-01-16 19:57:16
![](https://img.aspxhome.com/file/2023/7/91947_0s.png)
PhpStorm配置debug环境的详细过程
2023-05-26 20:04:32
python图书管理系统
2023-01-30 17:35:48
SQL Server数据库动态交叉表的参考示例
2009-01-04 14:44:00
谨慎使用PHP的引用原因分析
2023-09-09 10:37:13
python tkinter实现学生信息管理系统
2021-11-01 18:46:16
MySQL Order By用法
2011-01-04 19:50:00
Django DRF APIView源码运行流程详解
2022-10-29 01:21:44
![](https://img.aspxhome.com/file/2023/4/91954_0s.jpg)
python3 tkinter实现添加图片和文本
2022-08-07 04:28:17
![](https://img.aspxhome.com/file/2023/3/86133_0s.jpg)
Python可视化工具如何实现动态图表
2023-05-22 19:21:27
![](https://img.aspxhome.com/file/2023/0/81710_0s.gif)
Sklearn调优之网格搜索与随机搜索原理详细分析
2022-05-11 10:47:12