Python分类文件(大疆精灵4多光谱版PM4影象分类)

任务描述

大疆精灵4多光谱版有六个通道,每次拍摄都会生成六张图片。图片的顺序为 0. 可见光 1. 蓝光 2. 绿光 3. 红光 4. 红边 5. 近红外。
大疆PM4
在用其他软件进行拼接时需要对六个通道的照片分别进行拼接,而不同通道的图片仅是最后一位数字不同,因此要将相同通道的图片放到一起,易于利用软件拼接。
大疆PM4拍摄结果

代码实现

基于Python的os库和shutil库进行文件转移操作,代码如下

"""
author: Shuai-jie Shen 沈帅杰
优快云: https://blog.youkuaiyun.com/weixin_45452300
公众号: AgBioIT
"""
import shutil
import os

path = r'E:\博士期间记录\照片\站内\高光谱\20210811'
files = os.listdir(path)
rgb_file = path+'\\rgb'
red_file = path+'\\red'
green_file = path+'\\green'
blue_file = path+'\\blue'
red_edge_file = path+'\\red_edge'
Near_infrared_file = path+'\\nir'
for f in files:
    filename, suffix = os.path.splitext(f)  # filename是文件名 suffix是文件后缀
    if not os.path.exists(rgb_file):
        os.makedirs(rgb_file)
    if not os.path.exists(red_file):
        os.makedirs(red_file)
    if not os.path.exists(green_file):
        os.makedirs(green_file)
    if not os.path.exists(blue_file):
        os.makedirs(blue_file)
    if not os.path.exists(red_edge_file):
        os.makedirs(red_edge_file)
    if not os.path.exists(Near_infrared_file):
        os.makedirs(Near_infrared_file)
    if filename[-1] == '0':
        shutil.move(os.path.join(path, f), rgb_file)
    elif filename[-1] == '1':
        shutil.move(os.path.join(path, f), blue_file)
    elif filename[-1] == '2':
        shutil.move(os.path.join(path, f), green_file)
    elif filename[-1] == '3':
        shutil.move(os.path.join(path, f), red_file)
    elif filename[-1] == '4':
        shutil.move(os.path.join(path, f), red_edge_file)
    elif filename[-1] == '5':
        shutil.move(os.path.join(path, f), Near_infrared_file)

结果如下

在这里插入图片描述
在这里插入图片描述
如果你还想变回来可以运行一下代码

def de_classing_file(file_dir):
    """
    将文件夹子文件移动到上级目录
    :param file_dir:
    :return:
    """
    def get_all_files(dir, types):
        """
        获取文件夹列表函数
        :param dir: 文件夹所在位置
        :return: 文件夹内文件名称列表
        """
        files_ = []
        lit = os.listdir(dir)
        for i in range(0, len(lit)):
            path = os.path.join(dir, lit[i])
            if os.path.isdir(path):
                files_.extend(get_all_files(path, types))
            if os.path.isfile(path) and os.path.splitext(path)[1].lower() in types:
                files_.append(path)
        return files_
    files = get_all_files(file_dir, [".tif", ".tiff", ".jpg"])
    for i in files:
        shutil.move(i, file_dir)
path = r'E:\P4M_image_progressing\original_image\jining_images\rotation_exp20211013'
e_classing_file(path)
### 如何处理大疆多光谱数据 #### 工具介绍 Photoscan 是一款功能强大的软件,能够基于影像自动生成高质量的三维模型[^1]。它适用于多种类型的数据处理任务,包括无人机采集的多光谱数据。除了 Photoscan,其他类似的工具还包括 Pix4D、Global Mapper 和大疆智图等。然而,在实际应用中,许多用户倾向于选择 Photoscan 来完成此类任务,因为其在数据效果和效率方面表现优异。 #### 数据处理流程概述 对于来自大疆精灵4多光谱无人机拍摄的多光谱图像,可以通过 Agisoft Metashape Professional(即之前的 Photoscan)来实现高效处理[^2]。以下是具体的处理方式: #### 导入原始数据 首先,将由大疆无人机获取的多光谱图像导入到 Agisoft Metashape 中。这些图像通常具有较高的分辨率,并能捕捉多个波段的信息,从而为后续分析提供丰富的基础素材[^3]。 #### 构建密集点云与三角网格 利用软件内置算法对齐照片并构建密集点云,这是生成 DEM (Digital Elevation Model, 数字高程模型) 的重要前提之一。接着创建三角化表面以形成初步几何结构。 #### 提取单波段信息 为了获得特定需求下的单波段成果文件,可以在上述基础上进一步提取各个独立波段的相关参数值。这一步骤有助于深入研究目标区域内的植被健康状况或其他专题要素特征。 #### 生产DEM与DOM产品 最后一步则是分别生产出所需的 DEM 及 DOM(Digital Orthophoto Map, 数字正射影像地图)。前者反映了地面起伏情况;后者则提供了无畸变的真实比例尺平面投影图像资料。 ```python import photoscan as ps def process_multispectral_data(project_path): doc = ps.Document() chunk = doc.addChunk() # 添加新的数据块 # 加载图片路径列表 photo_paths = ["path/to/photo1", "path/to/photo2"] chunk.addPhotos(photo_paths) # 对齐照片 chunk.matchPhotos(accuracy=ps.HighAccuracy, preselection=ps.ReferencePreselection) chunk.alignCameras() # 构建密集点云 chunk.build.DenseCloud() # 创建高度场以及DSM/DTM chunk.buildDem(source=chunk.dense_cloud) # 正射校正生成DOM chunk.buildOrthomosaic(surface=chunk.elevations) # 输出最终结果至指定目录下保存项目文档 doc.save(path=f"{project_path}/output_project.psx") process_multispectral_data("/your/output/directory/") ``` 以上脚本展示了如何自动化执行整个工作流的一部分操作过程。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值