type
status
date
slug
summary
tags
category
titleIcon
password
icon
calloutIcon
📌
快速入门医学图像处理相关内容

MevisLab常用

用于医学图像(nii图,ply Mesh,etc.)可视化和常见处理模块

下载

如果进官网下载发现一片空白,就点击右上角English
notion image
然后自行下载安装
notion image

常用工作流

绘制标签覆盖图

ACDC为例:
notion image
View2D看2D图,逐切片
imagePropertyConvert用于转换视图矩阵
View3D看3D图
Threshold与标签值对应,表明对应图片标签值筛选,后续接染色重叠模块
notion image
可以选中View2D模块后在右边视图设置窗宽窗位
notion image
如果没有这一视图,勾选view/layout/developer
notion image

Mesh相关

  • 展示工作流(ASOCA为例)
notion image
notion image
  • 平滑与约简
notion image
 

常见问题

读不出NIfTI(nii)图像

图片类型可能是unsigned int类型,用SimpleITK或者nibabel读取后用numpy转换float类型保存再打开
notion image
notion image
示例代码:

python

import SimpleITK as sitk import numpy as np def process_image(input_path, output_path): image = sitk.ReadImage(input_path) image_array = sitk.GetArrayFromImage(image).astype(np.float32) processed_image = sitk.GetImageFromArray(image_array) processed_image.SetSpacing(image.GetSpacing()) processed_image.SetOrigin(image.GetOrigin()) processed_image.SetDirection(image.GetDirection()) sitk.WriteImage(processed_image, output_path) process_image("registered_label.nii.gz", "registered_label.nii.gz")
Python

Linux相关

SSH连接

对于一般用户在/home/用户名下,对root用户在/root下,创建.ssh文件夹,在其下创建authorized_keys文件
notion image
里面写入公钥
notion image
在vscode里按下ctrl+shift+p打开命令搜索ssh配置文件
notion image
打开后写入类似下文内容
主机名
服务器IP
用户名
端口
私钥位置
notion image
然后可以在remote explorer里找到SSH远程连接主机
notion image
如果仍连接不上,考虑:
1.主机是否安装ssh服务
2.是否允许ssh端口
3.公钥是否成功写入
4.当前用户是否具有连接的默认文件夹(一般是/home/用户名)的访问权限
Windows下:
生成公私钥命令:ssh-keygen -t rsa -b 4096
写入远程主机authorized_keys命令案例: scp E:/Core/ssh-lab/id_rsa.pub root@192.168.150.101:/root/.ssh/authorized_keys

tree指令的替代

用于查看文件的层次树形图,可用于VSCode SSH连不上的情况。

shell

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
Shell
notion image

tmux相关

用于ssh挂任务,可以在ssh会话断开后继续训练任务。
  • tmux 启动新窗口
    • 启动成功后会出现以下紫色条
notion image
  • 按键ctrl + b之后按d 回到原本的session(tmux开的不会退出,直到主动exit)
notion image
  • tmux list-sessions查看已开启会话
notion image
  • tmux attach -t 0(如上方的会话id)回到相应会话
  • 按键ctrl + b之后按 [ 键可以向上鼠标滚轮或按上方向键进行滑动查看输出

常用模块与库

TensorBoard可视化训练

notion image

简单示例

python

from tensorboardX import SummaryWriter tb_writer = SummaryWriter(log_dir=f'{dirs["tensorboard_out_dir"]}exp{fold}') tags = ["eval_loss", "learning_rate", "loss_ce", "loss_dc", "loss_kl", "loss_focal"] tb_writer.add_scalar(tags[0], mean_tloss / len(train_data), epoch) tb_writer.add_scalar(tags[1], scheduler.get_last_lr(), epoch) tb_writer.add_scalar(tags[2], mean_tloss_ce / len(train_data), epoch) tb_writer.add_scalar(tags[3], mean_tloss_dc / len(train_data), epoch) tb_writer.add_scalar(tags[4], mean_tloss_kl / len(train_data), epoch) tb_writer.add_scalar(tags[5], mean_tloss_focal / len(train_data), epoch) tb_writer.close()
Python

CE Loss与Dice Loss

CE loss Pytorch也有实现,Dice没有

简单示例

python

class CELoss(nn.Module): def __init__(self): super().__init__() def forward(self, y_true, y_pred): smooth = 1e-6 return -torch.mean(y_true * torch.log(y_pred + smooth)) class DiceLoss(nn.Module): def __init__(self): super(DiceLoss, self).__init__() def forward(self, logits, targets): class_num = logits.size(1) dice_sum = 0 x = 0 y = 0 for i in range(class_num): inter = torch.sum(logits[:, i, :, :] * targets[:, i, :, :]) union = torch.sum(logits[:, i, :, :]) + torch.sum(targets[:, i, :, :]) dice = (2.0 * inter + 1) / (union + 1) dice_sum += dice return 1 - dice_sum / class_num
Python

换卡训练

示例:export CUDA_VISIBLE_DEVICES=3 切换为3号卡
多卡用,分隔写多个就行
可以os模块的环境变量写入程序中

nnUNet

网络的源码不在nnUNet仓库里,在以下仓库:

点云可视化

可使用
notion image
 
天机学堂Day09-Day12复盘-优惠劵业务代码模版
Loading...
CamelliaV
CamelliaV
Java;CV;ACGN
最新发布
单例模式的四种写法
2025-4-24
体验MCP
2025-4-24
MetingJS使用自定义音乐源-CF+Huggingface部署
2025-4-2
博客访问站点测速分析与对比
2025-3-26
前端模块化
2025-3-16
Voxel2Mesh相关论文精读与代码复现
2025-3-15
公告
计划:
  • LLM相关
  • 支付业务 & 双token无感刷新
  • (线程池计算优惠方案)天机学堂Day09-Day12复盘-优惠劵业务
  • (业务复盘,技术汇总)天机学堂完结复盘
  • hot 100
 
2024-2025CamelliaV.

CamelliaV | Java;CV;ACGN