BDTC大会官网:https://t.csdnimg.cn/q4TY

作者 | chestnut--
来源 | CSDN博客

在医疗影像中特别是CT影像,包含大量的背景,在进行器官分割时,首先去除背景对分割的效果有很好的提升。本博客使用Python处理医疗影像并去除背景的影像。

使用的样例数据来自Multimodal Brain Tumor Segmentation Challenge 2018(https://www.med.upenn.edu/sbia/brats2018/registration.html)

读取数据的基本信息

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 problems
    start = 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=0
    tolerance=0.00001
    is_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] = 1
    return 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.shape
    if(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_max

def 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)

参考

3DUnetCNN

https://github.com/ellisdg/3DUnetCNN

3DUnet-Tensorflow-Brats18

https://github.com/tkuanlun350/3DUnet-Tensorflow-Brats18/blob/master/utils.py

扫码查看原文
▼▼▼

(*本文为AI科技大本营转载文章,转载联系原作者)

精彩推荐

2019 中国大数据技术大会(BDTC)再度来袭!豪华主席阵容及百位技术专家齐聚,15 场精选专题技术和行业论坛,超强干货+技术剖析+行业实践立体解读,深入解析热门技术在行业中的实践落地。6.6 折票限时特惠(立减1400元),学生票仅 599 元!
推荐阅读

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

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

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

  2. 深度学习在人脸检测中的应用 | CSDN 博文精选

    作者 | 梁志成.刘鹏.陈方杰 责编 | 唐小引 转载自CSDN(ID:csdnnews) 在目标检测领域,可以划分为人脸检测与通用目标检测,往往人脸这方面会有专门的算法(包括人脸检测.人脸识别.人脸 ...

  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系统, 国内相关 ...

最新文章

  1. 因用了Insert into select语句,同事被开除了!
  2. .NET 排序 Array.SortT 实现分析
  3. 案例分享|某医药集团的BI建设案例
  4. 绘图神器 —— Graphviz dot 语言介绍
  5. power bi 雷达图_【自助式数据分析平台——WonderBI(豌豆BI)】免费在线试用_软件库...
  6. Codeforces Round #518 (Div. 2) B LCM
  7. Vegas系列Movie Studio录制音频/乐的方法
  8. JavaScript基础1
  9. MySQL删除s表命令_SQL语句中删除表数据drop、truncate和delete的用法
  10. [C#] .NET4.0中使用4.5中的 async/await 功能实现异步
  11. SpringBoot系列(10):SpringBoot中的全局异常处理
  12. html系统网页代码大全,html网页的代码大全
  13. 生物信息学|Extracting Drug-Drug Interactions with Attention CNNs
  14. S@Kura的PHP进阶之路(二)
  15. 我要减肥~~~~~!!!(信誓旦旦)
  16. 鱼池显示服务器错误502,502+bad+gateway怎么解决
  17. 考驾照选择 AI 教练,心态稳定不会骂人
  18. 百度之星 2017初赛第一场 1005 今夕何夕
  19. 数据结构(python) —— 【29: 贪心算法之换钱问题】
  20. C_char*、char[]、中文字符

热门文章

  1. 折半查找函数(from 《The C Programming Language》)
  2. 突破电信3G宽带对网页浏览的上网限制
  3. shell shocked什么意思_Shell 启动类型探究 ── login interactive
  4. Eigen::Matrix
  5. boost thread 判断是否正在运行_java高端基础:Thread源码解读
  6. 暑期集训1:C++STL 例3:UVA-12100
  7. LaxTex---问题1: ! I can't write on file `***.pdf'.(Press Enter to retry, or Control-Z to exit; \ldots
  8. Spring 学习笔记
  9. python学习笔记(一)之入门
  10. 2017.9.12.语文