当前位置:网站首页>【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"))
}
边栏推荐
- 08 spark 集群搭建
- 90后的焦虑,被菜市场治好了
- 04 flink 集群搭建
- 【硬核拆解】50块2个的2022年夏季款智能节电器到底能不能省电?
- DOM series of touch screen events
- 夸克网盘资源站
- C#的CSV格式文件帮助类
- 金仓数据库 KingbaseES V8.3 至 V8.6 迁移最佳实践(4. V8.3 到 V8.6 数据库移植实战)
- The untiy Resources directory dynamically loads resources
- MySQL's maximum recommended number of rows is 2000w, is it reliable?
猜你喜欢
随机推荐
GridControl helper class for DevExpress
ESP8266-Arduino编程实例-GA1A12S202对数刻度模拟光传感器
C#的DataTable帮助类
月薪12K,蝶变向新勇往直前,我通过转行软件测试实现月薪翻倍...
显示为弹出窗口是什么意思(电脑总是弹出广告)
70后夫妻给苹果华为做“雨衣”,三年进账7.91亿
C# CSV format file helper class
首席工程师究竟是怎样的存在?
DOM系列之classList属性
nodejs安装淘宝镜像(配置淘宝镜像)
DOM树jsjs特效代码
DateTime Helper Class for C#
Bugku-Misc-贝斯手
AI艺术‘美丑’不可控?试试 AI 美学评分器~
MySQL locking case analysis
03 gp cluster construction
暑气渐敛,8月让我们开源一夏!
Ali's official Redis development specification
金仓数据库 MySQL 至 KingbaseES 迁移最佳实践(2. 概述)
测试技术|白盒测试以及代码覆盖率实践