做网站那家好,福建百度推广开户,莘庄做网站,1688免费货源网相关文章 PIL#xff0c;OPENCV之间的转换关系_pil cvtcolor(image)_番茄就要炒鸡蛋的博客-CSDN博客 python GDAL和PIL图像转换_gdal.readasarray和pil_llc的足迹的博客-CSDN博客 一、原始数据 二、分别读取数据 1、gdal读取的array 2、pil读取的array 三、 gdal转pil image … 相关文章 PILOPENCV之间的转换关系_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)imagegdal.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)imageimage.ReadAsArray()if atif:image np.rollaxis(image , 0, 3)image cv2.copyMakeBorder(image, top0, bottombottom_fill, left0, rightright_fill,borderTypecv2.BORDER_CONSTANT, value0)image cv2.copyMakeBorder(image, topstep_length // 2, bottomstep_length // 2, leftstep_length // 2,rightstep_length // 2,borderTypecv2.BORDER_CONSTANT, value0) # 填充1/2步长的外边框# 2.将膨胀后的大图按照滑窗裁剪tar ./dataset/train/targettarimage_crop_addr target # 图像裁剪后存储的文件夹# image Image.fromarray(image) # 将图片格式从numpy转回PILimageImage.fromarray(np.uint8(image))l 0if atif: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), quality95)l l 1if apng: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), quality95)l l 1