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

关于做网站的外语文献书名如何做公司网页制作

关于做网站的外语文献书名,如何做公司网页制作,有名vi设计公司,重庆企业服务建站网站开发文章目录 TIF图像转JPGTIF标签转PNG图像重叠裁剪图像重命名数据集转COCO格式数据集转VOC格式 遥感图像不同于一般的自然图像#xff0c;由于波段数量、图像位深度等原因#xff0c;TIF图像数据不能使用简单的格式转换方法。本文以Potsdam数据集为例#xff0c;制作能够直接用… 文章目录 TIF图像转JPGTIF标签转PNG图像重叠裁剪图像重命名数据集转COCO格式数据集转VOC格式 遥感图像不同于一般的自然图像由于波段数量、图像位深度等原因TIF图像数据不能使用简单的格式转换方法。本文以Potsdam数据集为例制作能够直接用于深度学习的数据集。 Potsdam数据集的内容如下 本文使用2_Ortho_RGB图像数据RGB通道顺序和5_Labels_all标签数据作为示例进行数据集制作。 TIF图像转JPG TIF转JPG借鉴了文章怎么读取tif格式的卫星遥感数据并将数据输入到神经网络模型中进行训练 # -*- coding: UTF-8 -*- import numpy as np import os from PIL import Image from osgeo import gdaldef readTif(imgPath, bandsOrder[1, 2, 3]):读取GEO tif影像的前三个波段值并按照R.G.B顺序存储到形状为【原长*原宽*3】的数组中:param imgPath: 图像存储全路径:param bandsOrder: RGB对应的波段顺序如高分二号多光谱包含蓝B绿g红R近红Nir外四个波段RGB对应的波段为321:return: R.G.B三维数组dataset gdal.Open(imgPath, gdal.GA_ReadOnly)cols dataset.RasterXSizerows dataset.RasterYSizedata np.empty([rows, cols, 3], dtypefloat)for i in range(3):band dataset.GetRasterBand(bandsOrder[i])oneband_data band.ReadAsArray()data[:, :, i] oneband_datareturn datadef stretchImg(imgPath, resultPath, lower_percent0.5, higher_percent99.5):#将光谱DN值映射至0-255并保存:param imgPath: 需要转换的tif影像路径***.tif:param resultPath: 转换后的文件存储路径(***.jpg):param lower_percent: 低值拉伸比率:param higher_percent: 高值拉伸比率:return: 无返回参数直接输出图片RGB_Array readTif(imgPath)band_Num RGB_Array.shape[2]JPG_Array np.zeros_like(RGB_Array, dtypenp.uint8)for i in range(band_Num):minValue 0maxValue 255# 获取数组RGB_Array某个百分比分位上的值low_value np.percentile(RGB_Array[:, :, i], lower_percent)high_value np.percentile(RGB_Array[:, :, i], higher_percent)temp_value minValue (RGB_Array[:, :, i] - low_value) * (maxValue - minValue) / (high_value - low_value)temp_value[temp_value minValue] minValuetemp_value[temp_value maxValue] maxValueJPG_Array[:, :, i] temp_valueoutputImg Image.fromarray(np.uint8(JPG_Array))outputImg.save(resultPath)def Batch_Convert_tif_to_jpg(imgdir, savedir):# 检查保存目录是否存在如果不存在则创建if not os.path.exists(savedir):os.makedirs(savedir)# 获取文件夹下所有tif文件名称并存入列表file_name_list os.listdir(imgdir)for name in file_name_list:# 获取图片文件全路径img_path os.path.join(imgdir, name)# 获取文件名不包含扩展名filename os.path.splitext(name)[0]savefilename filename .jpg# 文件存储全路径savepath os.path.join(savedir, savefilename)stretchImg(img_path, savepath)print(fConverted {filename} to jpg format.)print(Done!)# 主函数首先调用 if __name__ __main__:imgdir rF:\Potsdam\2_Ortho_RGB # tif文件所在的【文件夹】savedir rF:\Potsdam\jpg # 转为jpg后存储的【文件夹】Batch_Convert_tif_to_jpg(imgdir, savedir) TIF标签转PNG 如果标签图像是单通道的那么可以简单地进行格式转换以适应深度学习模型的输入要求。然而当标签图像以RGB格式存在时则需要使用RGB字典进行映射。 import os from PIL import Image import numpy as npdef rgb_to_single_channel(rgb_image_path, output_path, rgb_dict):将RGB图像转换为单通道图像使用指定的RGB字典来映射类别标签。:param rgb_image_path: RGB图像的路径:param output_path: 转换后图像的保存路径:param rgb_dict: RGB字典键是RGB元组值是对应的类别标签# 读取RGB图像rgb_image Image.open(rgb_image_path)# 将图像转换为numpy数组rgb_array np.array(rgb_image)# 创建一个空的单通道图像数组single_channel_array np.zeros((rgb_array.shape[0], rgb_array.shape[1]), dtypenp.uint8)# 将RGB值转换为单一的标量值for rgb, label in rgb_dict.items():# 将图像中的每个像素的RGB值与rgb_dict中的RGB元组进行比较# 如果匹配则将对应的类别标签赋给单通道图像的对应像素single_channel_array[np.all(rgb_array rgb, axis-1)] label# 将单通道数组转换为图像并保存single_channel_image Image.fromarray(single_channel_array, modeL)single_channel_image.save(output_path)def convert_tif_to_png(image_folder, output_folder, rgb_dict):将指定文件夹中的所有TIFF图像转换为PNG格式并保存到另一个文件夹中。如果图像是单通道图像则直接转换为PNG。如果图像是RGB图像则使用rgb_to_single_channel函数进行转换。:param image_folder: 包含TIFF图像的文件夹路径。:param output_folder: 保存转换后的PNG图像的文件夹路径。:param rgb_dict: RGB字典用于rgb_to_single_channel函数。# 检查输出文件夹是否存在如果不存在则创建它if not os.path.exists(output_folder):os.makedirs(output_folder)# 遍历图像文件夹中的所有文件for filename in os.listdir(image_folder):filepath os.path.join(image_folder, filename)# 检查文件是否为TIFF格式if filename.endswith(.tif):try:# 打开TIFF图像image Image.open(filepath)# 检查图像是否为单通道图像if image.mode L:# 如果是单通道图像直接转换为PNGoutput_filename os.path.splitext(filename)[0] .pngoutput_filepath os.path.join(output_folder, output_filename)image.save(output_filepath, PNG)print(fConverted {filename} to png format.)else:# 如果是RGB图像使用rgb_to_single_channel函数进行转换output_filename os.path.splitext(filename)[0] _single_channel.pngoutput_filepath os.path.join(output_folder, output_filename)rgb_to_single_channel(filepath, output_filepath, rgb_dict)print(fConverted {filename} to single channel png format.)except Exception as e:print(fError converting {filename}: {str(e)})# 指定图像文件夹和输出文件夹 image_folder rF:\Potsdam\5_Labels_all output_folder rF:\Potsdam\png# 定义RGB字典 rgb_dict {(255, 255, 255): 1, # 不透水路面 Impervious surfaces (RGB: 255, 255, 255)(0, 0, 255): 2, # 建筑物 Building (RGB: 0, 0, 255)(0, 255, 255): 3, # 低植被 Low vegetation (RGB: 0, 255, 255)(0, 255, 0): 4, # 树木 Tree (RGB: 0, 255, 0)(255, 255, 0): 5, # 汽车 Car (RGB: 255, 255, 0)(255, 0, 0): 255 # 背景 Clutter/background (RGB: 255, 0, 0) }# 调用函数进行转换 convert_tif_to_png(image_folder, output_folder, rgb_dict)图像重叠裁剪 由于遥感图像数据集的珍贵性我们可以使用重叠裁剪的方式扩充数据集数量当然也可以设置为0不重叠。 import os from PIL import Imagedef crop_images(image_path, save_path, subimage_size, overlap_ratio):将图像裁剪成指定大小的子图像并允许设置子图像之间的重叠比例。只有完全覆盖原始图像的子图像才会被保存。:param image_path: 原始图像路径:param save_path: 保存子图像的路径:param subimage_size: 子图像大小宽度和高度:param overlap_ratio: 子图像之间的重叠比例范围在0到1之间# 确保保存路径存在os.makedirs(save_path, exist_okTrue)# 遍历图像路径中的所有文件for filename in os.listdir(image_path):# 检查文件是否为图像格式if filename.lower().endswith((.png, .jpg, .jpeg, .bmp, .tif)):# 打开图像img Image.open(os.path.join(image_path, filename))width, height img.size# 计算子图像的步长包括重叠部分step int(subimage_size * (1 - overlap_ratio))# 计算需要划分的行列数num_rows (height // step) (1 if height % step 0 else 0)num_cols (width // step) (1 if width % step 0 else 0)# 遍历并保存每个子图片for row in range(num_rows):for col in range(num_cols):# 计算子图像的左上角和右下角坐标left col * steptop row * stepright left subimage_sizebottom top subimage_size# 检查子图像是否完全覆盖原始图像if right width and bottom height:# 裁剪子图像sub_img img.crop((left, top, right, bottom))# 构建子图像的文件名base_name, ext os.path.splitext(filename)sub_filename f{base_name}_row{row}_col{col}{ext}# 保存子图像sub_img.save(os.path.join(save_path, sub_filename))print(f{filename} cropping complete.)crop_images(rF:\Potsdam\jpg,rF:\Potsdam\jpg_512_0.5,512, 0.5)crop_images(rF:\Potsdam\png,rF:\Potsdam\png_512_0.5,512, 0.5) 图像重命名 在构建遥感图像数据集的过程中会遇到图像集和相应的标签集在文件命名上的不一致问题。这种不一致性会导致无法直接将数据集用于深度学习模型的训练因为模型通常需要图像和标签数据具有完全匹配的文件名以确保它们可以正确地配对。 import osdef rename(directory, str):# 检查目录是否存在if not os.path.exists(directory):print(path error)return# 获取目录下所有文件files os.listdir(directory)# 循环处理每个文件for file in files:if file.endswith((.png, .jpg, .jpeg, .bmp, .tif)):# 检查文件名中是否包含if str in file:# 构建新的文件名new_file_name file.replace(str, )# 旧文件路径old_file_path os.path.join(directory, file)# 新文件路径new_file_path os.path.join(directory, new_file_name)try:# 重命名文件os.rename(old_file_path, new_file_path)print(f {file} rename {new_file_name})except Exception as e:print(f {file} error{e})# 指定路径 jpg_directory_path rF:\Potsdam\jpg_512_0.5 png_directory_path rF:\Potsdam\png_512_0.5 jpg_str_RGB png_str_label_single_channel# 执行重命名操作 rename(jpg_directory_path, jpg_str) rename(png_directory_path, png_str)数据集转COCO格式 某些深度学习模型是根据公共自然图像数据集格式进行数据集格式处理这里给出COCO数据集的格式转化。 import os import json import shutil import random from PIL import Image# 原始JPG图片路径 jpg_path rF:\Five-Billion-Pixels\jpg_512 # 原始PNG标签路径 png_path rF:\Five-Billion-Pixels\png_24_512 # COCO数据集路径 coco_path rF:\Five-Billion-Pixels\coco-stuff# 确保COCO数据集路径存在 if not os.path.exists(coco_path):os.makedirs(coco_path)# 创建COCO数据集的目录结构 annotations_path os.path.join(coco_path, annotations) images_path os.path.join(coco_path, images) train_images_path os.path.join(images_path, train2017) val_images_path os.path.join(images_path, val2017) train_annotations_path os.path.join(annotations_path, train2017) val_annotations_path os.path.join(annotations_path, val2017)os.makedirs(annotations_path, exist_okTrue) os.makedirs(images_path, exist_okTrue) os.makedirs(train_images_path, exist_okTrue) os.makedirs(val_images_path, exist_okTrue) os.makedirs(train_annotations_path, exist_okTrue) os.makedirs(val_annotations_path, exist_okTrue)# 获取JPG图片列表 jpg_images [f for f in os.listdir(jpg_path) if f.lower().endswith(.jpg)]# 随机划分数据集 random.shuffle(jpg_images) split_index int(len(jpg_images) * 0.8) # 80%的数据用于训练20%的数据用于验证 train_images jpg_images[:split_index] val_images jpg_images[split_index:]# 复制图像和标签到对应的目录 def copy_images_and_labels(image_list, src_image_path, src_label_path, dst_image_path, dst_label_path):for image_name in image_list:# 复制图像shutil.copy(os.path.join(src_image_path, image_name), os.path.join(dst_image_path, image_name))# 复制标签label_name image_name.replace(.jpg, .png)shutil.copy(os.path.join(src_label_path, label_name), os.path.join(dst_label_path, label_name))# 复制训练集图像和标签 copy_images_and_labels(train_images, jpg_path, png_path, train_images_path, train_annotations_path)# 复制验证集图像和标签 copy_images_and_labels(val_images, jpg_path, png_path, val_images_path, val_annotations_path) 数据集转VOC格式 某些深度学习模型是根据公共自然图像数据集格式进行数据集格式处理这里给出VOC数据集的格式转化。 import os import shutil import randomdef create_voc_dataset(image_folder, label_folder):# 定义 VOC 数据集的主目录和子目录voc_root VOCdevkitvoc_dataset VOC2012voc_images os.path.join(voc_root, voc_dataset, JPEGImages)voc_labels os.path.join(voc_root, voc_dataset, SegmentationClassAug)voc_image_sets os.path.join(voc_root, voc_dataset, ImageSets, Segmentation)# 创建 VOC 数据集所需的目录结构os.makedirs(voc_images, exist_okTrue)os.makedirs(voc_labels, exist_okTrue)os.makedirs(voc_image_sets, exist_okTrue)# 遍历图像文件夹中的所有图像文件for root, dirs, files in os.walk(image_folder):for filename in files:if filename.endswith(.jpg):# 构建图像文件的完整路径image_path os.path.join(root, filename)# 构建 VOC 数据集中的图像路径voc_image_path os.path.join(voc_images, filename)# 将图像复制到 VOC 数据集目录shutil.copy(image_path, voc_image_path)print(图像已复制)# 遍历标签文件夹中的所有标签文件for root, dirs, files in os.walk(label_folder):for filename in files:if filename.endswith(.png):# 构建标签文件的完整路径label_path os.path.join(root, filename)# 构建 VOC 数据集中的标签路径voc_label_path os.path.join(voc_labels, filename)# 将标签复制到 VOC 数据集目录shutil.copy(label_path, voc_label_path)print(标签已复制)# 获取图像文件夹中的所有文件名不含扩展名image_filenames [os.path.splitext(filename)[0] for root, dirs, files in os.walk(image_folder) for filename in files if filename.endswith(.jpg)]# 随机打乱文件名列表random.shuffle(image_filenames)# 计算训练集和验证集的分割点split_index int(len(image_filenames) * 0.8)# 分割训练集和验证集train_files image_filenames[:split_index]val_files image_filenames[split_index:]# 生成 train.txt 文件train_file_path os.path.join(voc_image_sets, train.txt)with open(train_file_path, w) as train_file:for filename in train_files:train_file.write(filename \n)# 生成 val.txt 文件val_file_path os.path.join(voc_image_sets, val.txt)with open(val_file_path, w) as val_file:for filename in val_files:val_file.write(filename \n)# 打印成功提示信息print(train.txt 和 val.txt 已成功创建。)# 提供图像文件夹和标签文件夹的路径 image_folder rF:\WHDLD\Images label_folder rF:\WHDLD\Labels# 调用函数创建 VOC 数据集 create_voc_dataset(image_folder, label_folder)
文章转载自:
http://www.morning.qhmql.cn.gov.cn.qhmql.cn
http://www.morning.fgrcd.cn.gov.cn.fgrcd.cn
http://www.morning.yggdq.cn.gov.cn.yggdq.cn
http://www.morning.rrwgh.cn.gov.cn.rrwgh.cn
http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn
http://www.morning.svtxeu.com.gov.cn.svtxeu.com
http://www.morning.nlygm.cn.gov.cn.nlygm.cn
http://www.morning.uycvv.cn.gov.cn.uycvv.cn
http://www.morning.jmspy.cn.gov.cn.jmspy.cn
http://www.morning.lhxdq.cn.gov.cn.lhxdq.cn
http://www.morning.fnpmf.cn.gov.cn.fnpmf.cn
http://www.morning.jtcq.cn.gov.cn.jtcq.cn
http://www.morning.hzryl.cn.gov.cn.hzryl.cn
http://www.morning.qqhersx.com.gov.cn.qqhersx.com
http://www.morning.ckrnq.cn.gov.cn.ckrnq.cn
http://www.morning.fxzgw.com.gov.cn.fxzgw.com
http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn
http://www.morning.ydnx.cn.gov.cn.ydnx.cn
http://www.morning.ns3nt8.cn.gov.cn.ns3nt8.cn
http://www.morning.ymrq.cn.gov.cn.ymrq.cn
http://www.morning.hqrr.cn.gov.cn.hqrr.cn
http://www.morning.gmswp.cn.gov.cn.gmswp.cn
http://www.morning.fldrg.cn.gov.cn.fldrg.cn
http://www.morning.ckwrn.cn.gov.cn.ckwrn.cn
http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn
http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn
http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn
http://www.morning.fnjrh.cn.gov.cn.fnjrh.cn
http://www.morning.dnwlb.cn.gov.cn.dnwlb.cn
http://www.morning.wgzgr.cn.gov.cn.wgzgr.cn
http://www.morning.tyhfz.cn.gov.cn.tyhfz.cn
http://www.morning.qcslh.cn.gov.cn.qcslh.cn
http://www.morning.thpzn.cn.gov.cn.thpzn.cn
http://www.morning.jzxqj.cn.gov.cn.jzxqj.cn
http://www.morning.sgqw.cn.gov.cn.sgqw.cn
http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn
http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn
http://www.morning.pprxs.cn.gov.cn.pprxs.cn
http://www.morning.ccffs.cn.gov.cn.ccffs.cn
http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn
http://www.morning.dfffm.cn.gov.cn.dfffm.cn
http://www.morning.npgwb.cn.gov.cn.npgwb.cn
http://www.morning.pzlcd.cn.gov.cn.pzlcd.cn
http://www.morning.pqkgb.cn.gov.cn.pqkgb.cn
http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn
http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn
http://www.morning.gfpyy.cn.gov.cn.gfpyy.cn
http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn
http://www.morning.skdhm.cn.gov.cn.skdhm.cn
http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn
http://www.morning.fhddr.cn.gov.cn.fhddr.cn
http://www.morning.drfrm.cn.gov.cn.drfrm.cn
http://www.morning.jbfzx.cn.gov.cn.jbfzx.cn
http://www.morning.czcbl.cn.gov.cn.czcbl.cn
http://www.morning.pwppk.cn.gov.cn.pwppk.cn
http://www.morning.gyqnp.cn.gov.cn.gyqnp.cn
http://www.morning.srnth.cn.gov.cn.srnth.cn
http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn
http://www.morning.gbnsq.cn.gov.cn.gbnsq.cn
http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn
http://www.morning.blqmn.cn.gov.cn.blqmn.cn
http://www.morning.thpzn.cn.gov.cn.thpzn.cn
http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn
http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn
http://www.morning.myzfz.com.gov.cn.myzfz.com
http://www.morning.zwgbz.cn.gov.cn.zwgbz.cn
http://www.morning.qjngk.cn.gov.cn.qjngk.cn
http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn
http://www.morning.dhyzr.cn.gov.cn.dhyzr.cn
http://www.morning.cwqln.cn.gov.cn.cwqln.cn
http://www.morning.rqbr.cn.gov.cn.rqbr.cn
http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn
http://www.morning.pqndg.cn.gov.cn.pqndg.cn
http://www.morning.wtsr.cn.gov.cn.wtsr.cn
http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn
http://www.morning.mzqhb.cn.gov.cn.mzqhb.cn
http://www.morning.zkpwk.cn.gov.cn.zkpwk.cn
http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn
http://www.morning.tsyny.cn.gov.cn.tsyny.cn
http://www.morning.rdymd.cn.gov.cn.rdymd.cn
http://www.tj-hxxt.cn/news/236803.html

相关文章:

  • 有哪些学校的网站做的好处网站seo关键词优化
  • wordpress闭站建立平台需要什么
  • 百度网盘0基础网站开发教程网站文章编辑器代码
  • 网站流量查询站长之家上海影视传媒公司排名
  • 润商网站建设图片展示网站建设
  • 南宁站建站时间wordpress端口修改
  • 直播网站怎样建设甘肃省网站备案
  • 调查网站怎么做dt高端网站设计
  • 石家庄高端网站制作自己做的网站怎么嵌入高德地图
  • 甘肃建设厅网站执法局最新网站推广哪家好
  • app制作教程步骤图绍兴百度seo排名
  • 如何自己建设电商网站网络游戏排行榜2022
  • wordpress注明网站微网站怎么做的好名字吗
  • 合肥seo外包平台深圳推广软件十年乐云seo
  • 做citation的网站设计素材网站特点
  • 网站建设策划怎么谈仿站源码
  • 做网站的人跑了网站可以恢复吗响应式网站怎么改
  • 上海网站建设 网站开发wordpress上篇下篇代码
  • 电子商务网站软件建设核心免费cms建站系统
  • 做生鲜的网站公司网站主页排版
  • 中文域名网站标识wordpress 预订 插件
  • 百度官网认证网站淮北论坛最新招聘
  • 权威的手机网站制作苏州网站备案查询
  • 网站的开发设计的技术商务网站建设流程
  • 佛山外贸企业网站建设四川省城乡住房建设部网站
  • 北京金企鹅网站建设方案网站图片优化工具
  • 一般什么企业需要建站沈阳有资质做网站的公司
  • 布吉网站建设哪家好国和建设集团网站
  • 汕头市建筑信息网站一般的手机网站建设多少钱
  • express 网站开发网站开发的背景与环境