当前位置:网站首页>【R语言】对图片进行裁剪 图片批量裁剪
【R语言】对图片进行裁剪 图片批量裁剪
2022-08-01 16:34:00 【仿生bug】
对图片进行裁剪 / 批量裁剪
示例如图

# 对图片进行裁剪
library(magick)
pic <- image_read('study.jpg')
plot(pic)
print(pic)
image_info(pic)
# 500x300+10+20" –
# Crop image to 500 by 300 at position 10,20
# 后面的参数选择可以在Windows系统自带的画图软件截取计算
# 原始图片大小
width=image_info(pic)[2];height=image_info(pic)[3]
widthRange=158 # 截图的矩形框直接大小
heightRange=115
# 截取范围的起始 鼠标放在看【像素】
widthBegin=163
heightBegin=118
geometry=paste0(widthRange,"x",heightRange,
"+",widthBegin,"+",heightBegin)
# geometry = "widthRange x heightRange+widthBegin + heightBegin "
pic2=image_crop(pic,geometry = geometry)
plot(pic2)
# 图片保存
image_write(image = pic2,"pic2.jpg" )
#循环批量处理
lf <-list.files(pattern = "study")
(files <- gsub("", "", lf)) # 是否需要敏感字符替换处理
# 批量读取
piclist=lapply(files, function(x) {
image_read(x)})
# 裁剪
piclist2=lapply(piclist, function(x){
image_crop(x,geometry = geometry)})
# 保存
for (i in 1:length(piclist2)){
image_write(image = piclist2[[i]],paste0("pic",i,".jpg"))
}
边栏推荐
- 蚂蚁首次披露核心基础软件技术开源版图
- 参观首钢园
- 金仓数据库 KingbaseES V8.3 至 V8.6 迁移最佳实践(4. V8.3 到 V8.6 数据库移植实战)
- IronOS, an open source system for portable soldering irons, supports a variety of portable DC, QC, PD powered soldering irons, and supports all standard functions of smart soldering irons
- ESP8266-Arduino编程实例-GA1A12S202对数刻度模拟光传感器
- DOM series of touch screen events
- AI艺术‘美丑’不可控?试试 AI 美学评分器~
- AntDB数据库亮相24届高速展,助力智慧高速创新应用
- C# CSV format file helper class
- LeetCode Week 303
猜你喜欢
随机推荐
untiy Resorces目录动态加载资源
每日优鲜大败局
金仓数据库 KDTS 迁移工具使用指南(3. 系统部署)
Ant discloses the open source layout of core basic software technology for the first time
Vulnhub target drone: HARRYPOTTER_ NAGINI
金仓数据库 OCCI迁移指南(3. KingbaseES的OCCI特性支持)
2022年7月最热的10篇AI论文
C#Excel帮助类
C#的DateTime帮助类
DevExpress的GridControl帮助类
C#的DataTable帮助类
22年镜头“卷”史,智能手机之战卷进死胡同
Bugku-Misc-贝斯手
软测面试如何介绍项目?要做哪些技术准备?
uwsgi配置文件启动
全新升级!《云原生架构白皮书 2022 版》重磅发布
C#中关于DevExpress的常用操作和帮助类项目工程内容说明
清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
SQL函数 TIMESTAMPDIFF
DOM series of touch screen events









