
文件处理小程序
RuiXuan Zhang
遥感在读PhD,研究方向为灾害遥感智能化解译,公众号“Deep Mapping”
展开
-
python实现ROA算子边缘检测算法(以光学图像为例)
python实现ROA算子边缘检测算法讲解略代码import numpy as npimport cv2 as cvdef ROA(image_path, save_path, threshold): img = cv.imread(image_path) image = cv.cvtColor(img, cv.COLOR_RGB2GRAY) new = np.zeros((512, 512), dtype=np.float64) # 开辟存储空间 widt原创 2021-04-03 15:43:31 · 1665 阅读 · 7 评论 -
python实现深度学习中多图像叠置输出(以三张图片为例)
python实现深度学习中多图像叠置输出讲解略代码from PIL import Imagedef add_alpha_channel(img): img = Image.open(img) img = img.convert('RGBA') # 更改图像透明度 # factor = 0.7 # img_blender = Image.new('RGBA', img.size, (0, 0, 0, 0)) # img = Image.blend(原创 2021-12-09 13:29:50 · 3482 阅读 · 10 评论 -
批量获取精密轨道数据(python)
批量下载sentinel精密轨道数据原创 2022-06-22 13:48:50 · 1183 阅读 · 0 评论 -
python实现二分类分割精度评价指标批量计算并保存为txt文件(F1、mIoU、recall、precision、accuracy)
from PIL import Imageimport osimport json# 获取四个值# TP:被模型预测为正类的正样本(预测道路且标签道路)# TN:被模型预测为负类的负样本(预测背景且真实背景)# FP:被模型预测为正类的负样本(预测道路但真实背景)# FN:被模型预测为负类的正样本(预测背景但真实道路)def get_vaslue(predict_folders_path, label_folders_path): # 加载文件夹 predict_fold原创 2022-04-12 21:39:50 · 2091 阅读 · 4 评论 -
批量生成GF说明xlsx及产品号txt
import osimport pandas as pddef writefilename2excel(folder_path, excel_path, txt_path): # 加载文件夹 folder = os.listdir(folder_path) file_list = [] # 文件名 satellite_list = [] # 卫星 sensor_list = [] # 传感器 longitude_list = [] # 中心经度原创 2022-03-19 16:35:44 · 427 阅读 · 0 评论 -
python实现批量修改文件后缀
import osdef renaming(file): ext = os.path.splitext(file) if ext[1] == '.jpg': new_name = ext[0] + '.png' os.rename(file, new_name)def batch_opera(folder_path): folder = os.listdir(folder_path) for file in folder:原创 2022-03-16 10:06:56 · 978 阅读 · 0 评论 -
python实现图像固定尺寸批量缩放
python实现图像固定尺寸批量缩放import cv2import osif __name__ == "__main__": path = r'' # 目标文件夹路径 folders = os.listdir(path) for folder in folders: folder_path = os.path.join(path, folder) img = cv2.imread(folder_path) print(img原创 2021-10-04 22:06:57 · 381 阅读 · 0 评论 -
(接上)python实现批量深度学习数据增强
import cv2import mathimport numpy as npimport osclass data_stength: def __init__(self, imgae, rows, cols, center=[0, 0]): self.src = imgae # 图像 self.rows = rows # 行尺寸 self.cols = cols # 列尺寸 self.center = center原创 2021-09-28 20:32:23 · 400 阅读 · 0 评论 -
python实现Excel内数据转存
python实现Excel内数据转存import xlrdimport xlwtdef excel_demo(path, new_path): book = xlrd.open_workbook(path) table = book.sheets()[0] rows = int(table.nrows) cols = int(table.ncols) print("excel_size:{}行{}列".format(rows, cols)) num原创 2021-09-25 10:48:03 · 208 阅读 · 1 评论 -
python实现子文件夹中文件数目批量识别并导出条件子文件夹名单为Excel
python实现文件夹中文件数目批量识别并导出预选文件夹名单为Excel讲解略代码import osimport xlwt# 将数据写入新文件 file_path为目标Excel(不存在时会自动创建)def data_write(file_path, datas): f = xlwt.Workbook() sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True) j = -1 sheet1.writ原创 2021-08-03 16:42:30 · 430 阅读 · 4 评论 -
python实现基于八方向判断的断裂连接
python实现基于八方向判断的断裂连接讲解略代码''' 八方向连接算法'''import numpy as npimport matplotlib.image as mpimgfrom PIL import Imagedef compute_conv(fm, kernel, judge=None, kernel_num=3): [h, w] = fm.shape k = kernel_num r = int(k / 2) padding_fm =原创 2021-04-05 19:40:17 · 2394 阅读 · 11 评论 -
python实现批量提取指定文件夹下同类型文件
python实现批量提取指定文件夹下同类型文件讲解略代码import osimport shutildef take_samefile(or_path, tar_path, tar_type): tar_path = tar_path if not os.path.exists(tar_path): os.makedirs(tar_path) path = or_path files = os.listdir(path) # 读取or_pat原创 2021-04-03 09:31:05 · 1474 阅读 · 1 评论 -
python实现形态学操作(膨胀、侵蚀)
python实现形态学操作(膨胀、侵蚀)讲解略代码import cv2import numpy as npdef dilate(image_path, save_path): pic = image_path src = cv2.imread(pic, cv2.IMREAD_UNCHANGED) kernel = np.ones((5, 5), np.uint8) # 初始化窗口 dilate = cv2.dilate(src, kernel) # 侵蚀操原创 2021-04-02 12:51:03 · 1008 阅读 · 1 评论 -
python实现深度学习中原始图像与预测结果叠置输出
python实现深度学习中原始图像与预测结果叠置输出讲解略代码from PIL import Imagedef add_alpha_channel(img): img = Image.open(img) img = img.convert('RGBA') # 更改图像透明度 # factor = 0.7 # img_blender = Image.new('RGBA', img.size, (0, 0, 0, 0)) # img = Image.原创 2021-03-31 19:54:02 · 1800 阅读 · 9 评论 -
python实现labelme_json_to_dataset数据集标签批量提取
python实现对labelme_json_to_dataset内label批量提取讲解1、库:os,shutil2、代码效果:实现对labelme_json_to_dataset内label批量提取3、代码原理:用os.listdir()遍历文件同时用shutil.copy实现复制转存代码import osimport shutildef take_file_from_files_both_rename(or_path, tar_path): determination = o原创 2021-03-30 03:54:16 · 1642 阅读 · 8 评论 -
python实现固定尺寸图像拼接
python实现固定尺寸图像拼接讲解1、代码效果:固定尺寸图像拼接代码import osimport cv2import numpy as npdef joint(or_path, tar_path, size): determination = tar_path if not os.path.exists(determination): os.makedirs(determination) path = or_path folders =原创 2021-03-30 03:12:55 · 594 阅读 · 4 评论 -
python实现将原图裁剪为固定尺寸小图
python实现将原图裁剪为固定尺寸小图讲解1、代码效果:实现labelme_json_to dataset批量处理代码import numpy as npimport pandas as pdimport osimport torch as timport torchvision.transforms.functional as fffrom torch.utils.data import Datasetfrom PIL import Imageimport torchvision.原创 2021-03-30 03:07:17 · 3174 阅读 · 5 评论 -
python实现labelme_json_to_dataset批量处理
python实现labelme_json_to dataset批量处理讲解1、库:os2、代码效果:实现labelme_json_to dataset批量处理3、代码原理:os.system调用conda命令同时用os.listdir遍历代码import osdef labelme_bothall(path): path = path folders = os.listdir(path) folders_name = [] for folder in fol原创 2021-03-30 02:42:54 · 510 阅读 · 3 评论 -
python实现图像RGB拾取
python实现图像RGB拾取讲解1、库:PIL.Image2、代码效果:对指定图像内非背景RGB进行拾取3、代码原理:getpixel实现像素值拾取代码from PIL import Imagedef got_RGB(img_path): img = Image.open(img_path) width, height = img.size img = img.convert('RGB') array = [] for i in range(wid原创 2021-03-30 02:25:53 · 5161 阅读 · 5 评论 -
python实现文件夹分区
Python实现文件夹分区讲解1、库:os,shutil.copy2、代码效果:对指定文件夹内文件等量分配到新的文件夹3、代码原理:用os.listdir()遍历文件同时用shutil.copy实现复制转存代码import osfrom shutil import copydef folder_segmentation(path, new_path): i = 0 k = 0 save_dir = new_path if not os.path.isdir原创 2021-03-30 02:13:22 · 894 阅读 · 4 评论 -
python实现文件批量重命名
Python实现文件批量重命名讲解1、库:os2、代码效果:对指定文件夹内所有文件重命名为1,2,3…3、代码原理:使用os.listdir()遍历文件同时用os.rename()实现重命名代码import osdef reName(dirname): count = 0 for cur_file in os.listdir(dirname): count += 1 oldDir = os.path.join(dirname, cur_fil原创 2021-03-30 01:59:39 · 290 阅读 · 1 评论