在医疗影像中特别是CT影像,包含大量的背景,在进行器官分割时,首先去除背景对分割的效果有很好的提升。本博客使用python处理医疗影像并去除背景的影像。
使用的样例数据来自Multimodal Brain Tumor Segmentation Challenge 2018

读取数据的基本信息

import nibabel as nib
import numpy as np
from nilearn.image.image import _crop_img_to as crop_img_to
file = 'flair.nii.gz'
image = nib.load(file)
print(image.shape)

(240, 240, 155)

print(np.max(image.get_data()),np.min(image.get_data()))

470, 0
注意:0为背景像素值

显示其中的一个slice

import matplotlib.pyplot as plt
data = image.get_data()[:,:,52]
plt.imshow(data)

得到裁剪的空间位置坐标

def get_slice_index(data, rtol=1e-8):infinity_norm = max(-data.min(), data.max())passes_threshold = np.logical_or(data < -rtol * infinity_norm,data > rtol * infinity_norm)  ##if data.ndim == 4:passes_threshold = np.any(passes_threshold, axis=-1)coords = np.array(np.where(passes_threshold))start = coords.min(axis=1)end = coords.max(axis=1) + 1# pad with one voxel to avoid resampling problemsstart = np.maximum(start - 1, 0)end = np.minimum(end + 1, data.shape[:3])slices = [slice(s, e) for s, e in zip(start, end)]return slices

使用True 和False标记背景区域,背景像素值为False。

def have_back(image):background_value=0tolerance=0.00001is_foreground = np.logical_or(image.get_data() < (background_value - tolerance),image.get_data()> (background_value + tolerance))foreground = np.zeros(is_foreground.shape, dtype=np.uint8)foreground[is_foreground] = 1return foreground

调用,得到背景图标记,通过背景图标记得到坐标位置

foreground = have_back(image)
crop = get_slice_index(foreground)
print(crop)

[slice(45, 192, None), slice(47, 210, None), slice(0, 137, None)]
分别代表X,Y,Z的裁剪坐标

裁剪

image_o = crop_img_to(image, crop, copy=True)

image_o shape (147, 163, 137)

显示裁剪之后的结果

import matplotlib.pyplot as plt
data_o = image_o.get_data()[:,:,52]
plt.imshow(data_o)


对比着看一下:


以上参考的是[1]中的代码。
[2]中相同的处理方式,同时能够处理2D和3D。
整体的代码如下,主要使用到了get_none_zero_region和crop_ND_volume_with_bounding_box这两个函数:

def get_none_zero_region(im, margin):"""get the bounding box of the non-zero region of an ND volume"""input_shape = im.shapeif(type(margin) is int ):margin = [margin]*len(input_shape)assert(len(input_shape) == len(margin))indxes = np.nonzero(im)idx_min = []idx_max = []for i in range(len(input_shape)):idx_min.append(indxes[i].min())idx_max.append(indxes[i].max())for i in range(len(input_shape)):idx_min[i] = max(idx_min[i] - margin[i], 0)idx_max[i] = min(idx_max[i] + margin[i], input_shape[i] - 1)return idx_min, idx_maxdef crop_ND_volume_with_bounding_box(volume, min_idx, max_idx):"""crop/extract a subregion form an nd image."""dim = len(volume.shape)assert(dim >= 2 and dim <= 5)if(dim == 2):output = volume[np.ix_(range(min_idx[0], max_idx[0] + 1),range(min_idx[1], max_idx[1] + 1))]elif(dim == 3):output = volume[np.ix_(range(min_idx[0], max_idx[0] + 1),range(min_idx[1], max_idx[1] + 1),range(min_idx[2], max_idx[2] + 1))]elif(dim == 4):output = volume[np.ix_(range(min_idx[0], max_idx[0] + 1),range(min_idx[1], max_idx[1] + 1),range(min_idx[2], max_idx[2] + 1),range(min_idx[3], max_idx[3] + 1))]elif(dim == 5):output = volume[np.ix_(range(min_idx[0], max_idx[0] + 1),range(min_idx[1], max_idx[1] + 1),range(min_idx[2], max_idx[2] + 1),range(min_idx[3], max_idx[3] + 1),range(min_idx[4], max_idx[4] + 1))]else:raise ValueError("the dimension number shoud be 2 to 5")return output

使用:

margin = 5
bbmin, bbmax = get_none_zero_region(arr, margin)
bbmin, bbmax

([34, 17], [171, 191])

arr为2D或者3D的矩阵。

volume = crop_ND_volume_with_bounding_box(arr, bbmin, bbmax)

参考

  1. 3DUnetCNN
  2. 3DUnet-Tensorflow-Brats18

【医疗影像处理】去除医疗影像中背景的影响2D/3D【numpy-code】相关推荐

  1. 医疗影像处理:去除医疗影像中背景的影响2D/3D【numpy-code】| CSDN博文精选

    BDTC大会官网:https://t.csdnimg.cn/q4TY 作者 | chestnut-- 来源 | CSDN博客 在医疗影像中特别是CT影像,包含大量的背景,在进行器官分割时,首先去除背景 ...

  2. 如何去除Landsat影像中的水体呢?

    主要使用的是归一化差分植被指数 NDWI NDWI = (RED-NIR)/(RED+NIR) 这个指数提取出来后,网上说可以使用MATLAB所自带的函数graythresh 但是事实上,这个阈值不能 ...

  3. 国产心电芯片在互联网+医疗健康、智慧医疗、远程医疗、移动医疗背景下的发展

    互联网+医疗健康.智慧医疗.远程医疗.移动医疗背景下,智能可穿戴设备正成为改变医疗体系和人类健康的"新技术".         市场研究机构IDC最新发布的报告显示,2020年第四 ...

  4. 人工智能在医学影像中的研究与应用

    人工智能在医学影像中的研究与应用 韩冬, 李其花, 蔡巍, 夏雨薇, 宁佳, 黄峰 沈阳东软医疗系统有限公司,辽宁 沈阳 110167 慧影医疗科技(北京)有限公司,北京 100192 东软集团股份有 ...

  5. 沈定刚,雷柏英,李超 | Cell Press Live:人工智能在医学影像中的应用

    交叉学科 Interdisciplinary 医学影像是临床医疗诊断的重要依据之一.近些年来,随着信息技术的飞速发展,人工智能即AI也更加广泛地应用于医学影像的处理分析中,包括对图像的分割分类及预测等 ...

  6. 计算机在医学影像中的应用,计算机图像处理技术在医学影像中的进展与应用

    计算机图像处理技术在医学影像中的进展与应用 (4页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 4.9 积分 生物医学工程学杂志 J . Biou led ...

  7. 智慧医疗、互联网医疗相关术语

    智慧医疗.互联网医疗相关术语 医院信息系统(HIS) 全称Hospital Information System. HIS是覆盖医院所有业务和业务全过程的信息管理系统.利用电子计算机和通讯设备,为医院 ...

  8. 云栖科技评论第72期:医疗AI,医疗健康产业的“核按钮”

    [卷首语] 忽然之间,美国食品药物管理局(以下简称FDA)成了AI医疗亲密无间的好朋友和坚定的支持者. 2018年上半年,FDA相继批准癫痫监测与警报AI手表Embrace.AI临床监测平台Wave. ...

  9. 【转】C#开发PACS医学影像处理系统(一):开发背景和功能预览

    转自:https://www.cnblogs.com/Uncle-Joker/p/13646949.html 本系列文章将从以下模块和大家分享和讨论使用C#开发医学软件PACS和RIS系统, 国内相关 ...

  10. 专题·医疗数据安全 | 面向医疗信息系统的安全管理实践

    据<2021 年中国卫生健康统计年鉴>的数据显示,2020 年全国医疗机构总数达 35394 家,其中综合医院 20133 家,占比57%,其次是专科医院占比 25%.中医医院占比13%, ...

最新文章

  1. 如何使用OpenCV和Socket进行视频聊天?
  2. python能写软件吗-python代码能做成软件吗
  3. 让皮肤美白细致的七大DIY - 生活至上,美容至尚!
  4. 黑客借“甲型流感”传毒 挂马疾病预防控制中心网站
  5. Tuscany SCA 发布Web Service
  6. TZOJ 5640: 数据结构实验:仓库管理
  7. android socket第三方库,OkSocket 一个Android轻量级Socket通讯框架
  8. 4 基于优化的攻击——CW
  9. bat命令打开指定网页进入全屏
  10. linux交叉编译libnet,交叉编译samba(mipsel-linux) samba-3.3.3.tar.gz
  11. Win7 开机后3分钟内硬盘等狂闪解决办法
  12. 华为手机获取root权限
  13. 关于字符、字符集、编码和Unicode
  14. Unity_AR_Vuforia_实现涂涂乐
  15. 编程达人教你如何快速掌握一门编程语言附技术书阅读方法论
  16. 『喜报』WoS数据C1和EM字段不再重复
  17. Bag标签之轻开B2C电子商务网站登录校验实例
  18. matlab建立mex,Visual Studio创建Matlab mex(dll)函数
  19. 定期存款可以提前取出来吗_定期存款可以提前取出来吗 定期存款提前取出利息是怎么算的...
  20. coco2017数据集高速下载地址

热门文章

  1. XPath 元素及属性查找
  2. OpenGL学习笔记(一)OpenGL坐标变换
  3. blog转到CNBlog了
  4. Beyond Compare 4常用配置
  5. asp.net下ajax.ajaxMethod使用方法
  6. Gitlab+Jenkins学习之路(四)之gitlab备份和恢复
  7. Scala学习教程笔记三之函数式编程、集合操作、模式匹配、类型参数、隐式转换、Actor、...
  8. Codeforces Round #450
  9. [转]手把手教你搭建Hive Web环境
  10. Win7使用之查端口,杀进程