多模态图像配准融合——UMF-CMGR网络复现测试(详细图文教程)的跟学版

#python anaconda


前言

 历时四天,终于跟学成功复现UMF-CMGR项目。在此,感谢原作者开源了源代码,官网源码地址为Github,从作者的论文和源码中学到了很多,感谢原作者。另外还要感谢博主视觉研坊的博客教学,让我较为快速的复现UMF-CMGR项目。建议想复现项目的同学先去学习博主的文章多模态图像配准融合,我这个只能算作补丁版本。。

一、UMF-CMGR框架

首先,如果是看UMF-CMGR开源项目中的Readme的同学可能会有点疑惑,怎么在项目中还有个子项目CPSTN。

我先来大致介绍一下,主框架:图像准备(一定要是256*256大小)——生成扭曲变形图——配准——融合。副框架:运行CPSTNR——得到自己的伪红外图像。副框架参与主框架的配准、融合过程。

二、环境准备

1.Anaconda

这个我就不多赘述,需要的自行去博客里搜索下载。

2.环境配置

这是Github中列出的环境配置。笔者的电脑为win10系统,显卡是3050.pytorch-2.1.0 CUDA11.8

下面列出我的环境中下载的包 。

# Name                    Version                   Build  Channel
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
beautifulsoup4            4.12.3             pyha770c72_0    conda-forge
beniget                   0.4.1              pyhd3eb1b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
blas                      1.0                         mkl
brotli                    1.0.9                h827c3e9_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
brotli-bin                1.0.9                h827c3e9_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
brotli-python             1.0.9            py38hd77b12b_8
build                     0.10.0           py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
ca-certificates           2025.2.25            haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
certifi                   2024.8.30        py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
charset-normalizer        3.3.2              pyhd3eb1b0_0
clang                     14.0.6               haa95532_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
clang-14                  14.0.6          default_h120b48b_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
clangxx                   14.0.6          default_h120b48b_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
click                     8.1.7           win_pyh7428d3b_0    conda-forge
cloudpickle               3.0.0            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
contourpy                 1.0.5            py38h59b6b97_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cuda-cccl                 12.8.90                       0    nvidia
cuda-cccl_win-64          12.8.90                       0    nvidia
cuda-cudart               11.8.89                       0    nvidia
cuda-cudart-dev           11.8.89                       0    nvidia
cuda-cupti                11.8.87                       0    nvidia
cuda-libraries            11.8.0                        0    nvidia
cuda-libraries-dev        11.8.0                        0    nvidia
cuda-nvrtc                11.8.89                       0    nvidia
cuda-nvrtc-dev            11.8.89                       0    nvidia
cuda-nvtx                 11.8.86                       0    nvidia
cuda-profiler-api         12.8.90                       0    nvidia
cuda-runtime              11.8.0                        0    nvidia
cuda-version              12.8                          3    nvidia
cycler                    0.11.0             pyhd3eb1b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cython                    3.0.11           pyh02c11ea_103    conda-forge
cytoolz                   0.12.2           py38h2bbff1b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
dask-core                 2023.4.1         py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
docker-pycreds            0.4.0                      py_0    conda-forge
dominate                  2.9.1              pyhd8ed1ab_0    conda-forge
enum34                    1.1.10           py38h32f6830_2    conda-forge
filelock                  3.13.1           py38haa95532_0
fonttools                 4.51.0           py38h2bbff1b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
freetype                  2.12.1               ha860e81_0
fsspec                    2025.3.0                 pypi_0    pypi
gast                      0.5.3              pyhd3eb1b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
gitdb                     4.0.7              pyhd3eb1b0_0
gitpython                 3.1.41             pyhd8ed1ab_0    conda-forge
icu                       73.1                 h6c2663c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
idna                      3.7              py38haa95532_0
imagecodecs-lite          2019.12.3        py38hbaf524b_6    conda-forge
imageio                   2.27.0             pyh24c5eb1_0    conda-forge
importlib-metadata        8.5.0              pyha770c72_0    conda-forge
importlib_resources       6.4.0            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
intel-openmp              2023.1.0         h59b6b97_46320
jinja2                    3.1.4            py38haa95532_0
jpeg                      9e                   h827c3e9_3
jsonpatch                 1.33               pyhd8ed1ab_0    conda-forge
jsonpointer               3.0.0            py38haa244fe_0    conda-forge
kiwisolver                1.4.4            py38hd77b12b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
kornia                    0.5.10                   pypi_0    pypi
krb5                      1.20.1               h5b6d351_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
lazy-loader               0.4                pyhd8ed1ab_1    conda-forge
lcms2                     2.16                 hb4a4139_0
lerc                      4.0.0                h5da7b33_0
libblas                   3.9.0              26_win64_mkl    conda-forge
libbrotlicommon           1.0.9                h827c3e9_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libbrotlidec              1.0.9                h827c3e9_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libbrotlienc              1.0.9                h827c3e9_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libcblas                  3.9.0              26_win64_mkl    conda-forge
libclang                  14.0.6          default_hb5a9fac_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libclang-cpp              14.0.6          default_h120b48b_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libclang13                14.0.6          default_h8e68704_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libcublas                 11.11.3.6                     0    nvidia
libcublas-dev             11.11.3.6                     0    nvidia
libcufft                  10.9.0.58                     0    nvidia
libcufft-dev              10.9.0.58                     0    nvidia
libcurand                 10.3.9.90                     0    nvidia
libcurand-dev             10.3.9.90                     0    nvidia
libcusolver               11.4.1.48                     0    nvidia
libcusolver-dev           11.4.1.48                     0    nvidia
libcusparse               11.7.5.86                     0    nvidia
libcusparse-dev           11.7.5.86                     0    nvidia
libdeflate                1.22                 h5bf469e_0
libffi                    3.4.4                hd77b12b_1
libjpeg-turbo             2.0.0                h196d8e1_0
liblapack                 3.9.0              26_win64_mkl    conda-forge
libnpp                    11.8.0.86                     0    nvidia
libnpp-dev                11.8.0.86                     0    nvidia
libnvjpeg                 11.9.0.86                     0    nvidia
libnvjpeg-dev             11.9.0.86                     0    nvidia
libpng                    1.6.39               h8cc25b3_0
libpq                     17.4                 h70ee33d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libprotobuf               3.20.3               h23ce68f_0
libtiff                   4.5.1                h44ae7cf_1
libuv                     1.48.0               h827c3e9_0
libwebp-base              1.3.2                h3d04722_1
locket                    1.0.0            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
lz4-c                     1.9.4                h2bbff1b_1
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
markupsafe                2.1.3            py38h2bbff1b_0
matplotlib                3.7.2            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
matplotlib-base           3.7.2            py38h4ed8f06_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
mkl                       2023.1.0         h6b88ed4_46358
mkl-service               2.4.0            py38h2bbff1b_1
mkl_fft                   1.3.8            py38h2bbff1b_0
mkl_random                1.2.4            py38h59b6b97_0
mpmath                    1.3.0            py38haa95532_0
msys2-conda-epoch         20160418                      1    conda-forge
networkx                  2.8.8              pyhd8ed1ab_0    conda-forge
ninja                     1.12.1               haa95532_0
ninja-base                1.12.1               h4157e71_0
numpy                     1.24.3           py38h79a8e48_1
numpy-base                1.24.3           py38h8a87ada_1
opencv-python             3.4.10.35                pypi_0    pypi
openjpeg                  2.5.2                hae555c5_0
openssl                   3.0.16               h3f729d1_0
packaging                 24.2               pyhd8ed1ab_2    conda-forge
partd                     1.4.1            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pathlib                   1.0.1            py38haa244fe_7    conda-forge
pillow                    10.4.0           py38h827c3e9_0
pip                       24.2             py38haa95532_0
platformdirs              4.3.6              pyhd8ed1ab_0    conda-forge
ply                       3.11                     py38_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pooch                     1.8.2              pyhd8ed1ab_0    conda-forge
protobuf                  3.20.3           py38haa244fe_1    conda-forge
psutil                    5.9.0            py38h2bbff1b_0
pyparsing                 3.0.9            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pyproject_hooks           1.0.0            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pyqt                      5.15.10          py38hd77b12b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pyqt5-sip                 12.13.0          py38h2bbff1b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pysocks                   1.7.1            py38haa95532_0
python                    3.8.20               h8205438_0
python-dateutil           2.9.0post0       py38haa95532_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
python_abi                3.8                      2_cp38    conda-forge
pythran                   0.15.0           py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pytorch                   2.1.0           py3.8_cuda11.8_cudnn8_0    pytorch
pytorch-cuda              11.8                 h24eeafa_6    pytorch
pytorch-mutex             1.0                        cuda    pytorch
pywavelets                1.4.1            py38h2bbff1b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pyyaml                    6.0.2            py38h827c3e9_0
qt-main                   5.15.2              h19c9488_12    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
requests                  2.32.3           py38haa95532_0
scikit-image              0.19.3           py38hd77b12b_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
scipy                     1.10.1           py38h1aea9ed_0    conda-forge
sentry-sdk                2.19.2             pyhd8ed1ab_0    conda-forge
setproctitle              1.2.2           py38h2bbff1b_1004
setuptools                75.1.0           py38haa95532_0
sip                       6.7.12           py38hd77b12b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
six                       1.16.0             pyh6c4a22f_0    conda-forge
smmap                     6.0.0              pyhd8ed1ab_1    conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    conda-forge
spin                      0.3              py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
sqlite                    3.45.3               h2bbff1b_0
sympy                     1.11.1           py38haa95532_0
tbb                       2021.8.0             h59b6b97_0
tifffile                  2019.7.26.2              py38_0    conda-forge
toml                      0.10.2             pyhd3eb1b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
tomli                     2.0.1            py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
toolz                     0.12.0           py38haa95532_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
torchaudio                2.1.0                    pypi_0    pypi
torchvision               0.16.0                   pypi_0    pypi
tornado                   6.2              py38h91455d4_1    conda-forge
tqdm                      4.67.1             pyhd8ed1ab_0    conda-forge
typing_extensions         4.11.0           py38haa95532_0
ucrt                      10.0.22621.0         h57928b3_1    conda-forge
unicodedata2              15.1.0           py38h2bbff1b_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
urllib3                   2.2.3            py38haa95532_0
vc                        14.42                haa95532_4
visdom                    0.2.4              pyhd8ed1ab_0    conda-forge
vs2015_runtime            14.42.34433          he0abc0d_4
wandb                     0.16.6             pyhd8ed1ab_1    conda-forge
websocket-client          1.8.0              pyhd8ed1ab_0    conda-forge
wheel                     0.44.0           py38haa95532_0
win_inet_pton             1.1.0            py38haa95532_0
xsimd                     12.1.1               h59b6b97_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
xz                        5.6.4                h4754444_1
yaml                      0.2.5                he774522_0
zipp                      3.21.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h8cc25b3_1
zstd                      1.5.6                h8880b57_0

笔者记得在下载scikit-image时耗费了许多时间,后来上官网查询才知道下载这个包还需要提前先下载好其它的包. 在下载kornia时需要合适的版本。

3.在pycharm中使用conda类型环境 

第一步 使用pycharm打开UMF-CMGR-main后,请看这篇文章pycharm终端设置

第二步 请看这篇文章 pycharm中选择创建的虚拟环境

三 、运行脚本 

这一步照着视觉工坊的博客学就行 。提示:脚本中的有些代码是由问题的,当运行发现报错后可以通过AI来进行修正,因为每个人的情况会不一样。这个就依靠自己来解决问题。

这是图片的重命名代码

import os
import shutil

class BatchRename():
    '''
    批量重命名文件夹中的图片文件

    '''
    def __init__(self):
        self.path = r'E:\Project\UMF-CMGR-main\CPSTN\datasets\Calibration_plate\fake_ir_01\rgb2ir_paired_Road_edge_pretrained\test_latest\images'  #表示需要命名处理的文件夹
        self.save_path=r'E:\Project\UMF-CMGR-main\dataset\raw\ctest\fake_Road\fake_ir_rename'#保存重命名后的图片地址
    def rename(self):
        filelist = os.listdir(self.path) #获取文件路径
        # filelist.sort(key=lambda x: int(x.split('.')[0])) # 先按照名称顺序排好序
        filelist.sort(key=lambda x: int(x.split('_')[1].split('.')[0]))  # 先按照名称顺序排好序
        total_num = len(filelist) #获取文件长度(个数)
        i = 1  #表示文件的命名是从1开始的
        for item in filelist:
            print(item)
            if item.endswith('.png'):  #初始的图片的格式为jpg格式的(或者源文件是png格式及其他格式,后面的转换格式就可以调整为自己需要的格式即可)
                src = os.path.join(os.path.abspath(self.path), item)#当前文件中图片的地址
                dst = os.path.join(os.path.abspath(self.save_path), 'FLIR_'+str(i).zfill(5) + '.jpg')#处理后文件的地址和名称,可以自己按照自己的要求改进
                try:
                    #os.rename(src, dst)
                    shutil.copy(src, dst)
                    print ('converting %s to %s ...' % (src, dst))
                    i = i + 1
                except:
                    continue
        print ('total %d to rename & converted %d jpgs' % (total_num, i))

if __name__ == '__main__':
    demo = BatchRename()
    demo.rename()

这是更改图片大小的代码

from PIL import Image
import os

def resize_images(input_folder, output_folder):
    # 检查输出文件夹是否存在,如果不存在则创建
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    # 遍历输入文件夹中的所有文件
    for filename in os.listdir(input_folder):
        file_path = os.path.join(input_folder, filename)
        # 检查是否为图像文件
        if os.path.isfile(file_path) and filename.lower().endswith(('.png', '.jpg', '.jpeg')):
            try:
                # 打开图像
                image = Image.open(file_path)
                # 调整图像大小为 256x256
                resized_image = image.resize((256, 256), Image.LANCZOS)
                # 构建输出文件路径
                output_path = os.path.join(output_folder, filename)
                # 保存调整后的图像
                resized_image.save(output_path)
                print(f"已处理 {filename}")
            except Exception as e:
                print(f"处理 {filename} 时出错: {e}")

 最后,关于视觉工坊博主提到的配置参数,可以根据自己的伪红外图像、红外图像、可见光图像的路径不同进行更改。例如我的

--dataroot
E:\Project\UMF-CMGR-main\dataset\raw\ctest\Road\vi
--name
rgb2ir_paired_Road_edge_pretrained
--model
test
--no_dropout
--preprocess
none
--results_dir
E:\Project\UMF-CMGR-main\CPSTN\datasets\Calibration_plate\fake_ir_01
--checkpoints_dir
E:\Project\UMF-CMGR-main\CPSTN\checkpoints

补充, 配置参数在这儿输入


总结

笔者第一次写博客,如有不足请宽恕。

主要还是跟着视觉工坊博主进行复现,我这个算补丁。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值