python实现对任意大小图片均匀切割的示例
作者:ACGlyt 时间:2022-05-07 06:17:05
改代码是在windows 系统下
打开路径和保存路径换成自己的就可以啦~
import numpy as np
import matplotlib
import os
def img_seg(dir):
files = os.listdir(dir)
for file in files:
a, b = os.path.splitext(file)
img = Image.open(os.path.join(dir + "\\" + file))
hight, width = img.size
w = 256
id = 1
i = 0
while (i + w <= hight):
j = 0
while (j + w <= width):
new_img = img.crop((i, j, i + w, j + w))
#rename = "D:\\labelme\\images\\"
rename = "D:\\labelme\\annotations\\"
new_img.save(rename + a + "_" + str(id) + b)
id += 1
j += w
i = i + w
if __name__ == '__main__':
#path = "D:\\labelme\\data\\images\\train"
path = "D:\\labelme\\data\\dataset_png"
img_seg(path)
来源:https://blog.csdn.net/u011582187/article/details/79842037
标签:python,图片,切割
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP分页类(支持多风格变换)
2011-04-08 10:39:00
![](https://img.aspxhome.com/file/UploadPic/20112/5/201125112048960.jpg)
Go 加密解密算法小结
2024-04-26 17:29:00
python3 字符串/列表/元组(str/list/tuple)相互转换方法及join()函数的使用
2023-09-10 17:20:38
2009淘宝网动画节日LOGO第一季
2009-05-18 19:11:00
golang 实现tcp server端和client端,并计算RTT时间操作
2023-08-30 14:12:49
$.browser.msie 为空或不是对象问题的多种解决方法
2024-05-11 09:33:55
python 函数定位参数+关键字参数+inspect模块
2023-07-05 23:04:37
Linux oracle数据库自动备份自动压缩脚本代码
2024-01-19 01:44:40
Python-split()函数实例用法讲解
2023-12-12 07:13:20
python 使用pygame工具包实现贪吃蛇游戏(多彩版)
2021-05-10 17:29:19
![](https://img.aspxhome.com/file/2023/3/105383_0s.jpg)
vue项目持久化存储数据的实现代码
2024-04-27 15:59:48
python jenkins 打包构建代码的示例代码
2022-10-05 02:22:02
Yii2框架实现登陆添加验证码功能示例
2023-11-21 11:36:32
Python asyncore socket客户端实现方法详解
2022-06-18 14:17:42
![](https://img.aspxhome.com/file/2023/5/133435_0s.png)
详解Python if-elif-else知识点
2022-02-23 16:06:23
Go语言入门13之runtime包案例讲解
2024-02-02 05:54:08
搞定web设计中网页路径问题
2007-09-22 08:52:00
Git科普文,Git基本原理及各种骚操作(推荐)
2023-09-16 17:04:32
![](https://img.aspxhome.com/file/2023/9/132349_0s.jpg)
Mootools 1.2教程(12)——用Drag.Move实现拖拽和拖放
2008-12-05 12:29:00
碰到MySQL无法启动1067错误问题解决方法
2024-01-18 09:16:47
![](https://img.aspxhome.com/file/2023/2/105692_0s.jpg)