我的目的主要是利用 nibabel 这个库来处理一些 NIFTI 格式的  医学方面的数据。

官方的网址如下:

https://nipy.org/nibabel/nibabel_images.html#the-image-object

首先, 自然是安装库, 然后我们使用 load 函数来读取一个 nii.gz格式的文件,

它 return 的是一个  <class 'nibabel.nifti1.Nifti1Image'>   类型的 object

import nibabel as nib
img = nib.load(example_file)

关于 这个return 回来的数据类型, 我们要知道如下的三点:

(n维数组, 代表图像,  仿射变换  , meta_data)

A nibabel image object is the association of three things:

  • an N-D array containing the image data;

  • a (4, 4) affine matrix mapping array coordinates to coordinates in some RAS+ world coordinate space (Coordinate systems and affines);

  • image metadata in the form of a header.

#  demo

简单的读取,  查看return 的 object 的类型 和 shape

if __name__ == '__main__':demo_img, demo_seg = load_case(cid=123)print(type(demo_img))print(demo_img.shape--------------- output  ----------<class 'nibabel.nifti1.Nifti1Image'>
(61, 512, 512)

#  使用 get_fdata , 就可以转为float 为 dtype 的 ndarray类型的 object

    hu_data = demo_img.get_fdata()print(hu_data.shape)print(type(hu_data))print(hu_data.dtype)——————————————--------output-- - - -----------<class 'nibabel.nifti1.Nifti1Image'>
(61, 512, 512)
<class 'numpy.ndarray'>
float64

#  你可能也见过这个函数 get_data 缺少了一个‘ f ’ ,

I'm working with Nibabel to read some .nii files.I came across different examples and some of them use get_data() functionwhile some of them use get_fdata() function.I could not find what the difference is in their documentation (nibabel manuel).Can anyone explain?

在这里可以找到 https://nipy.org/nibabel/reference/nibabel.dataobj_images.html
(也就是get_data 和 get_fdata 的一些区别)

二者的一些说明如下:

get_data(caching='fill')Return image data from image with any necessary scaling applied
get_fdata(caching='fill', dtype=)Return floating point image data with necessary scaling applied

简单的来说, 一个是返回原数据, 一个则是返回浮点数。

就是这么点区别

不过有一点需要注意 , 这个get_data 函数要被取缔了:

We recommend you use the get_fdata method instead of the get_data method,because it is easier to predict the return data type.
We will deprecate the get_data method around April 2018,
and remove it around April 2020.If you don’t care about the predictability of the return data type,
and you want the minimum possible data size in memory,
you can replicate the array
that would be returned by img.get_data() by using np.asanyarray(img.dataobj).

nibabel库 - 初步相关推荐

  1. matlab对nii文件处理,使用Nibabel库对nii格式图像的读写操作

    因为后期主要的研究方向是医学图像处理,而现有手头的大部分数据都是nii格式或者是hdr,img格式的数据,所以首先第一步我们需要解决图像的读写问题. 其实使用OpenCV也可以方便的进行图像读取,但是 ...

  2. python 笔记:打开nii格式(nibabel 库)

    1 nii格式介绍 1.0 Analyze 格式 在解释NII(NIFTI,neuroimaging information technology initiative)格式之前,我们需要先知道一下A ...

  3. GMSSL开源库--初步接触SM2

    2021SC@SDUSC 目录 一.整体情况 二.sm2_asn1.c 一.整体情况 在有关OPENSSL的一本书上看到了OPENSSL部分目录功能说明,Crypto目录中存放OpenSSL所有加密算 ...

  4. C++ Boost库初步使用 - 使用CFree

    首先下载并安装 Boost: 在CFree中编写代码如下: #include <windows.h> #include "resource.h" #include &l ...

  5. python+遗传算法+Geatpy库—初步认识

    重要参考: (48条消息) 遗传算法(geatpy)_hellobigorange的博客-CSDN博客_geatpy 1,安装(Anaconda+geatpy) Anaconda安装遗传和进化算法库函 ...

  6. Linux系统编程24:基础IO之在Linux下深刻理解C语言中的动静态库以及头文件和库的关系

    文章目录 七:动态库和静态库 (1)什么是库 (2)静态库和动态库初步认识 A:静态库 B:动态库 C:头文件和库文件的关系 七:动态库和静态库 (1)什么是库 库就是现有的,已经写好的可复用的代码. ...

  7. 同步MySQL跨库且不同shema表数据

    场景:需要同步线上mysql指定表中数据到新版本开发环境的mysql库 初步计划用shell脚本同步. #!/bin/bashdb1_host="" db1_port=" ...

  8. bat文件无法保存为ansi_数组矩阵和PNG保存为nii文件

    nii文件或者nii.gz文件是一种特殊的文件格式,可以存储叠加的切片数据或者时序数据,比如MRI头部矢状面扫描的所有切片,CT扫描图,多细胞时移图等等.对于nii文件的读取和存储也有许多的方法. 一 ...

  9. sock 文件方式控制宿主机_sock

    使用select实现I/O复用2021-01-12 23:57:39 实验条件:在使用一个服务器,多个客户端的情况下,实现回声效果,即客户端传什么内容给服务器,服务器将该内容返回. 具体实现:每个客户 ...

最新文章

  1. 常用地理数据平台及环境数据资源 (GIS)
  2. python工程师证书-【一个合格的Python工程师需要达到怎样的编程水平】
  3. Redis之通用的key操作命令
  4. HDU - 1536 S-Nim(sg函数)
  5. 40名大学生被退学,教育部表态:学生对自己不负责,就要付出代价
  6. 支付宝王益:40岁写30年代码是一种什么体验?
  7. jquery.pin 修改浮动的top元素
  8. 又出问题!特斯拉回应384万天价充电费:系统错误,正在修复
  9. hdu1113 Word Amalgamation(详解--map和string的运用)
  10. ubuntu11.04(unix 就可以了) 共享文件以及支持上传文件
  11. rtklib学习——DCB改正
  12. 【iOS教程】SideLoadly自签名IPA 教程
  13. 为什么学习Linux系统?
  14. 清华计算机系本科毕业起薪,大学本科毕业起薪最高的六大专业
  15. Android总结(1-3章)
  16. Java项目对接天眼查
  17. “幽幽远远”正式开张了,但是我的心情没有往日的开怀
  18. sap pp模块中的物料反冲
  19. linux pc98模拟器,在android上模拟PC98方法
  20. CA证书(数字证书原理)

热门文章

  1. 集成百度云推送,Android8.0系统推送收不到问题解决方案
  2. 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的
  3. nginx正向代理的配置和使用
  4. js 数组全排列组合算法
  5. Paper:Transformer模型起源—2017年的Google机器翻译团队—《Transformer:Attention Is All You Need》翻译并解读
  6. 今年第一所大学改考408!广东工业大学
  7. 服务器系统 设置开关机,服务器开关机设置方法
  8. ZT收购NewNet的移动和物联网消息传送及交互语音事业部
  9. GoDaddy域名添加不带www的域名CNAME记录
  10. python-02 总结