matnrrd NRRD文件读取

matnrrd是一个MATLAB库,提供易于使用的函数来加载和保存NRRD文件。将matnrrd与其他NRRD读者区分开来的一个特性是它将元数据字段解析为合理的数据类型。
要使用此库,请在MATLAB路径中的某处复制/粘贴nrrdread.m和nrrdwrite.m。你准备好了!
 
例子:
 
[data,metadata] = nrrdread(’data / test1d_ascii.nrrd’);
[data,metadata] = nrrdread(’data / test3d_bigendian_raw_noendianfield.nrrd’,’Endian’,’big’);
 
[data,metadata] = nrrdread(’data / test1d_ascii.nrrd’);
metadata.encoding =’raw’;
nrrdwrite(’test.nrrd’,数据,元数据);
 
元数据
 
该功能的主要优点之一是元数据
从字符串解析并转换为合理的数据类型。这是
针对NRRD规范中指定的字段执行。
 
结构用于在MATLAB中存储元数据字段。一个警告
使用结构的关键是键不能有空格。
由于NRRD格式包括具有空格的字段,因此空格是
阅读时删除。 fieldMap键被添加到结构中
包含一个Nx2单元格数组。第一列表示密钥名称
MATLAB元数据结构和第二列包含实际
带空格的字段名称。这样可以保留字段名称中的空格
使用nrrdwrite保存NRRD文件。
 
以下是支持的字段列表及其对应的MATLAB
他们转换为的数据类型:
* dimension – int [必需]
* lineskip – int
* byteskip – int
*空间维度 – int
*分钟 – 双倍
*最大 – 双倍
* oldmin – 双倍
* oldmax – 双倍
* type – string [REQUIRED]
* endian – 字符串
* encoding – string [REQUIRED]
*内容 – 字符串
* sampleunits – 字符串
* datafile – 字符串
*空格 – 字符串
*尺寸 – 1xN整数矩阵[必需]
*间距 – 双倍的1xN矩阵
*厚度 – 1xN双倍矩阵
* axismins – 双倍的1xN矩阵
* axismaxs – 双倍的1xN矩阵
*种类 – 字符串的Nx1单元格数组
* labels – Nx1单元格字符串数组
*单位 – 字符串的Nx1单元格数组
* spaceunits – 字符串的Nx1单元格数组
* centerings – 字符串的Nx1单元格数组
* spacingirections – MxN矩阵的双精度
* spaceorigin – 双倍的MxN矩阵
* measurementframe – 整数的MxN矩阵
 
上表中列出的大多数字段都是可选的
四个例外。 NRRD文件必须包含类型,尺寸,
大小和编码字段。
 
注意:对于间隔,NRRD允许为a指定none
特定维度表示它不是空间域。
NRRDREAD将使所有NaN的矩阵的第一行发出信号
这个维度是没有的。例如:
空间方向:无(1,0,0)(0,1,0)(0,0,1)
将变成:
[NaN NaN NaN; 1 0 0; 0 1 0; 0 0 1]
 
对于不受支持的字段,将显示警告,值将显示
留下一个字符串。
 
通过报告错误或贡献代码帮助解决:
https://github.com/addisonElliott/matnrrd
 
在线查看格式规范:
http://teem.sourceforge.net/nrrd/format.htmlmatnrrd is a MATLAB library that provides ea
sy-to-use functions for loading and saving NRRD files. One feature that sets matnrrd apart from other NRRD readers is that it parses the metadata fields into sensible datatypes.
To use this library, copy/paste nrrdread.m and nrrdwrite.m somewhere in your MATLAB path. You are ready to go!
Examples:
[data, metadata] = nrrdread(‘data/test1d_ascii.nrrd’);
[data, metadata] = nrrdread(‘data/test3d_bigendian_raw_noendianfield.nrrd’, ‘Endian’, ‘big’);

[data, metadata] = nrrdread(‘data/test1d_ascii.nrrd’);
metadata.encoding = ‘raw’;
nrrdwrite(‘test.nrrd’, data, metadata);

METADATA
One of the main advantages of this function is that the metadata is
parsed from strings and turned into a sensible datatype. This is
performed for the fields specified in the NRRD specification.
A structure is used to store the metadata fields in MATLAB. One caveat
of using a structure is that the keys cannot have spaces in them.
Since the NRRD format includes fields with spaces, the spaces are
removed when reading. A fieldMap key is added to the structure that
contains a Nx2 cell array. The first column signifies the key name in
the MATLAB metadata structure and the second column contains the actual
field name with spaces. This preserves the spaces in field names when
using nrrdwrite to save an NRRD file.
Here is a list of supported fields and their corresponding MATLAB
datatype they are converted to:
* dimension – int [REQUIRED]
* lineskip – int
* byteskip – int
*
space dimension – int
* min – double
* max – double
* oldmin – double
* oldmax – double
* type – string [REQUIRED]
* endian – string
* encoding – string [REQUIRED]
* content – string
* sampleunits – string
* datafile – string
* space – string
* sizes – 1xN matrix of ints [REQUIRED]
* spacings – 1xN matrix of doubles
* thicknesses – 1xN matrix of doubles
* axismins – 1xN matrix of doubles
* axismaxs – 1xN matrix of doubles
* kinds – Nx1 cell array of strings
* labels – Nx1 cell array of strings
* units – Nx1 cell array of strings
* spaceunits – Nx1 cell array of strings
* centerings – Nx1 cell array of strings
* spacedirections – MxN matrix of doubles
* spaceorigin – MxN matrix of doubles
* measurementframe – MxN matrix of ints
Most of the fields listed in the table above are optional with the
exception of four. The NRRD file must contain the type, dimension,
sizes and encoding fields.
Note: For spacedirections, NRRD allows specifying none for a
particular dimension to indicate it is not a spatial domain.
NRRDREAD will make the first row of the matrix all NaN’s to signal
that it is none for the dimension. For example:
space directions: none (1,0,0) (0,1,0) (0,0,1)
will turn into:
[NaN NaN NaN; 1 0 0; 0 1 0; 0 0 1]
For unsupported fields, a warning will be displayed and the value will
be left as a string.
Help out by reporting bugs or contributing code at:
https://github.com/addisonElliott/matnrrd
See the format specification online:
http://teem.sourceforge.net/nrrd/format.html

为您推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注