交流qq群:651587317
1、转化为数组
-*- coding: utf-8 -*-
from PIL import Image
from pylab import *
#读取图片并转为数组
im = array(Image.open("C:\\Users\\Administrator\\Desktop\\22.png"))
#输出数组的各维度长度以及类型
print im.shape,im.dtype
#输出位于坐标100,100,颜色通道为r的像素值
print im[100,100,0]
#输出坐标100,100的rgb值
print im[100,100]及类型
print im.shape,im.dtype
2、 获取每一个像素值
im = im.convert("RGB")
r,g,b = im.getpixel((10,10))
3、图片切割
先 pip install Pillow
from PIL import Image
def cut_pic(pic_filepath,cut_pic_filepath,index):
u''' 裁剪图片
:param pic_filepath 需要裁剪图片url
:param cut_pic_filepath 裁剪后图片存储的url
:param index 裁剪坐标字典 example index = {"left":20,"upper":20,"right":20,"lower":20 }
:return False:裁剪失败 True :裁剪成功
:example cut_pic(pic_filepath,cut_pic_filepath,index)
'

这篇博客介绍了如何使用Python将图片转化为数组,包括读取图片、获取像素值和进行图片切割。通过PIL库,可以方便地操作图片的像素数据,如查看特定位置的RGB值,并实现图片的裁剪功能。
最低0.47元/天 解锁文章
3413

被折叠的 条评论
为什么被折叠?



