当前位置:网站首页>【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"))
}
边栏推荐
- UI helper class for Winform - some components will use DevExpress components
- Bugku-Misc-贝斯手
- uwsgi配置文件启动
- 90后的焦虑,被菜市场治好了
- DOM树jsjs特效代码
- AntDB数据库亮相24届高速展,助力智慧高速创新应用
- 显示为弹出窗口是什么意思(电脑总是弹出广告)
- ESP8266-Arduino编程实例-MLX90614红外测温传感器驱动
- HashCode technology insider interview must ask
- 2022 Strong Net Cup CTF---Strong Net Pioneer ASR wp
猜你喜欢
随机推荐
04 flink 集群搭建
每日优鲜大败局
Path helper class for C#
11 Publish a series as soon as it is released
mysql源码分析——聚簇索引
使用Canvas实现网页鼠标签名效果
The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!
年化收益高的理财产品
8年软件测试工程师感悟 —— 写给还在迷茫中的朋友
08 spark 集群搭建
C#Excel帮助类
AntDB数据库亮相24届高速展,助力智慧高速创新应用
短剧正在抢长剧的生意
70后夫妻给苹果华为做“雨衣”,三年进账7.91亿
Ant discloses the open source layout of core basic software technology for the first time
PAT 甲级 A1003 Emergency
Isometric graph neural networks shine in drug discovery
金仓数据库 KDTS 迁移工具使用指南(3. 系统部署)
Vulnhub靶机:HARRYPOTTER_ NAGINI
ESP8266-Arduino编程实例-GA1A12S202对数刻度模拟光传感器









