当前位置: 首页 > news >正文

用gdal库读取tif影像并填充边缘,并根据窗口大小滑动裁剪裁剪(包含gdal转PIL)

相关文章

PIL,OPENCV之间的转换关系_pil cvtcolor(image)_番茄就要炒鸡蛋的博客-CSDN博客

python GDAL和PIL图像转换_gdal.readasarray和pil_llc的足迹的博客-CSDN博客

一、原始数据

二、分别读取数据

1、gdal读取的array 

2、pil读取的array

 

三、 gdal转pil

image= np.rollaxis(image , 0, 3)

 转换结果

总的代码 

用gdal库读取tif影像并填充边缘,并根据窗口大小滑动裁剪裁剪

​
def clip_picture(file_path,a):slide_window = 1024  # 大的滑动窗口step_length = 1024sat_list = os.listdir(file_path) for file in sat_list:Image_Path = os.path.join(file_path,file)image=gdal.Open(Image_Path)width = image.RasterXSizeheight = image.RasterYSize# image = Image.open(Image_Path)# width = image.size[0]  # 获取图像的宽# height = image.size[1]  # 获取图像的高right_fill = step_length - (width % step_length)bottom_fill = step_length - (height % step_length)width_path_number = int((width + right_fill) / step_length)  # 横向切成的小图的数量height_path_number = int((height + bottom_fill) / step_length)  # 纵向切成的小图的数量#print(width_path_number, height_path_number)# image = np.array(image)image=image.ReadAsArray()if a=='tif':image= np.rollaxis(image , 0, 3)image = cv2.copyMakeBorder(image, top=0, bottom=bottom_fill, left=0, right=right_fill,borderType=cv2.BORDER_CONSTANT, value=0)image = cv2.copyMakeBorder(image, top=step_length // 2, bottom=step_length // 2, left=step_length // 2,right=step_length // 2,borderType=cv2.BORDER_CONSTANT, value=0)  # 填充1/2步长的外边框# 2.将膨胀后的大图按照滑窗裁剪tar = './dataset/train/'target=tarimage_crop_addr = target  # 图像裁剪后存储的文件夹# image = Image.fromarray(image)  # 将图片格式从numpy转回PILimage=Image.fromarray(np.uint8(image))l = 0if a=='tif':for j in range(height_path_number):for i in range(width_path_number):box = (i * step_length, j * step_length, i * step_length + slide_window, j * step_length + slide_window)small_image = image.crop(box)small_image.save(image_crop_addr + file[:-4] + '({},{})@{:04d}_sat.tif'.format(j, i, l), quality=95)l = l + 1if a=='png':for j in range(height_path_number):for i in range(width_path_number):box = (i * step_length, j * step_length, i * step_length + slide_window, j * step_length + slide_window)small_image = image.crop(box)small_image.save(image_crop_addr + file[:-4] + '({},{})@{:04d}_mask.png'.format(j, i, l), quality=95)l = l + 1​

http://www.lryc.cn/news/128512.html

相关文章:

  • sqlserver数据库导出到mysql
  • 【抓包工具】whistle抓包工具分享
  • docker可视化工具Portainer
  • 售后服务管理系统哪家好?云部署的售后服务软件有什么优势?
  • laravel-admin之 解决上传图片不显示 $form->image(‘image‘); 及 $grid->column(‘image‘);
  • 运营商三要素 API:构建安全高效的身份验证系统
  • 使用 BERT 进行文本分类 (01/3)
  • layui第三方组件cron的使用
  • Linux 信号的基本概念
  • 神经网络基础-神经网络补充概念-31-参数与超参数
  • C# Linq源码分析之Take (二)
  • FPGA控制RGB灯WS2812B
  • 【Linux】【驱动】应用层和驱动层传输数据
  • 【第二阶段】kotlin函数引用
  • sip网络号角喇叭 sip音柱 POE供电广播音箱 ip网络防水对讲终端 sip网络功放
  • 【网络】传输层——TCP(滑动窗口流量控制拥塞控制延迟应答捎带应答)
  • Electron教程_编程入门自学教程_菜鸟教程-免费教程分享
  • LVS负载均衡DR(直接路由)模式
  • 14 anaconda+pycharm环境管理以及源管理
  • 【C语言程序设计】C语言基本数据类型与表达式(思考题)
  • Linux 网络发包流程
  • Python web实战之Django的AJAX支持详解
  • spring boot实现实体类参数自定义校验
  • 网络安全威胁与防御策略
  • C++:哈希表——模拟散列表
  • 项目配置中心介绍
  • 14-案例:购物车
  • 上海市青少年算法2023年2月月赛(丙组)
  • jetpack5.0.2 已经安装了 cudnn 和 tensorrt
  • 我的编程语言学习笔记