当前位置:网站首页>dicom格式转成nii.gz文件
dicom格式转成nii.gz文件
2022-06-21 12:04:00 【老油条666】
# -*-coding:utf-8-*-
import glob
import os
import shutil
from tqdm import tqdm
import monai
from monai.transforms import LoadImage, Compose, LoadImaged, Orientationd, EnsureChannelFirstd, SaveImage, AddChanneld, \
AddChannel
data_dir = r'D:\Caiyimin\Dicom_data\Oral_image_root\KaWaAndSenTianOrg'
nii_save_path = r'D:\Caiyimin\Dicom_data\Oral_image_root\NiiFormat'
def has_dcm_files(path):
for _, _, files in os.walk(path):
if len(files) == 0:
return False
else:
return True
transform = Compose(
LoadImaged(keys=['image'], meta_keys='info'),
Orientationd(keys=["image"], axcodes='LPS'),
)
def convert2nii():
for root, dirs, _ in os.walk(data_dir):
for (i, dir) in enumerate(tqdm(dirs)):
abs_dir = os.path.join(root, dir)
key = {"image": abs_dir}
info = transform(key)
img = info['image']
img = AddChannel()(img)
saver = SaveImage(output_dir=nii_save_path, mode='bilinear', output_postfix='')
meta_data = info['info']
saver(img, meta_data=meta_data)
# 将保存文件移到上一个目录中
nii_files = glob.glob(os.path.join(nii_save_path, dir, '*.nii.gz'))
for file in nii_files:
file_name = file.split('\\')[-1]
shutil.move(file, os.path.join(nii_save_path, file_name))
shutil.rmtree(os.path.join(nii_save_path, dir))
convert2nii()边栏推荐
- Formation harmonyos I
- Adapter power supply automatic test equipment | introduction to charger ATE test system nsat-8000
- 2-zabbix automatically add hosts using autodiscover
- Corrigendum to 138 sets of reference solutions to the real problems of Higher Algebra in 2022
- 记录一次pytorch训练模型遇到的报错
- A recovery solution of system paralysis caused by upgrading glibc of VMware virtual machine
- Apache ShardingSphere 5.1.2 发布|全新驱动 API + 云原生部署,打造高性能数据网关
- STL基本容器测试
- Related codes of findpanel
- 华为云发布桌面IDE-CodeArts
猜你喜欢

2-zabbix automatically add hosts using autodiscover

Nanjing University static program analyses -- Introduction learning notes

Brief discussion on four full bonding processes of oca\uv-oca loca\sloca

Compilation de l'environnement vs Code + GCC développé par stm32

浅论OCA\UV-OCA LOCA\SLOCA 四种全贴合工艺

Rename all files in the folder with one click

南京大学 静态软件分析(static program analyzes)-- Intermediate Representation 学习笔记

Ansible 配置首次ssh免认证的操作说明

i. MX - rt1052 boot start

一文掌握SQLite3基本用法
随机推荐
动手学数据分析 数据重构
Introduction to CPU, MPU, MCU, SOC and MCM
动手学数据分析 数据可视化
External-Attention-tensorflow(更新中)
i. MX - rt1052 boot start
【云原生 | Devops篇】Jenkins安装与实战(二)
Jenkins 通过Build periodically配置定时任务
STM32笔记之 SWJ(JTAG-DP和 SW-DP)
HMS core machine learning service ID card identification function to achieve efficient information entry
tensorflow中使用的一些函数
STM32开发之 VS Code + GDB下载调试
STL basic container test
2-zabbix automatically add hosts using autodiscover
知识点:PCB电路板的几种特殊布线方法
广东发产品检测券,消费者也有份
2022年138套数学分析高等代数考研真题参考解答勘误
[untitled]
MySQL-DML
XML entity injection vulnerability
为什么世界上只有13个根域名服务器