brain images: Change data type of brain image

1 min read

Last update: 2012/09/04

An image file can be saved in different formats such as uint8 or int16, etc, based on different number of bytes used for each voxel. How to convert between them? Here is one solution using SPM functions (no need SPM’s interface). Assume img1.img is the original image with datatype int16, img2.img is the file you want to create with datatype uint8.

V=spm_vol('img1.img');
disp(V.dim); %you will find the last element is 4 in SPM2
V2=V;
V2.fname='img2.img';
V2.dim(4)=2;
M=spm_read_vols(V);
spm_write_vol(V2, M);

Explanation:
Variable V.dim is a 1×4 vector. The first three are number of voxels (or dimensions) along x,y and z direction. The last element (4th) is the number of bytes used for each voxel and it is this variable we want to change.

Note: If you are using SPM5 or SPM8, then the data type information is in V.dt

V=spm_vol('img1.img');
disp(V.dt); %for SPM5 and SPM8
V2=V;
V2.fname='img2.img';
V2.dt=[2 0];
M=spm_read_vols(V);
spm_write_vol(V2, M);

I myself find the following 3 SPM functions are extremely useful and use them a lot:

V=spm_vol('img1.img'); % read header information of an image file
M=spm_read_vols(V); % read the data (voxel intensity) from an image. The result is a 3D matrix with each point corresponding to a point in brain.
spm_write_vol(V2, M); % write data to an image file.

Check out here to see how to convert images with different formats (e.g. ANALYZE, Nifti, DICOM etc)

采用基于频率簇(Cluster)的置换检验(Permutation)方法选取感兴趣频段

作者:北京师范大学 龙宇航,longyuhangwork@163.com代码来源(见本页底部):周思远 在使用wtc计算脑间神经同步后,我们需要在多个频率段、多个通道组合上对神经同步值进行统计检验,因此当进行频段选择时,面临多重比较的问题。为了解决多重比较的问题,可以采取基于参数或非参数检验的多重比较矫正的方法。由于基于非参数检验的多重比较矫正对数据的分布形态没有严格要求,因此具有更广泛的应用场景 (Maris and Oostenveld, 2007)。本文即介绍基于随机置换的非参数检验的方法 (Zheng et al., 2020; Long et al., 2021)。 在寻找感兴趣的效应时,我们采取了基于频率簇(Cluster)的方法,即在频率方向寻找连续显著的Cluster,该方法比基于最强效应点的方法具有更为优秀的抗噪音能力。值得注意的是,我们并没有沿着通道的方向去寻找连续显著的通道簇,这是因为沿着通道方向寻找Cluster容易受到生理噪音的影响。 下面进入具体的实操部分。假设本例招募了22对组1被试及22对组2被试,每对被试分别进行3种条件的任务,因此本例是2(组别,被试间因素)*3(条件,被试内因素)的实验设计。本例对神经同步值进行2*3的混合方差分析,并关注交互作用。 具体来讲,进行置换检验需要进行以下几个步骤:1. 重采样;2. 对随机样本进行计算及统计;3. 计算真实样本的统计量;4. 真实样本与随机样本的对比。下面依次进行介绍。 1. 重采样...
Xu Cui
1 min read

第二十期 fNIRS Journal Club 通知 2021/06/26,10:00am

同时用fNIRS和EEG测量脑信号有哪些好处?技术上应该注意什么?美国斯坦福大学李日辉博士,将为大家讲解他做过的一个同时用fNIRS和EEG测量的实验。热烈欢迎大家参与讨论。 时间: 北京时间2021年6月26日上午10:00地点: https://zoom.com房间号: 856 9352 0230密码: 695930 李博士要讲解的文章如下: Li, Li, Roh, Wang, Zhang (2020) Multimodal Neuroimaging Using Concurrent EEG/fNIRS for Poststroke Recovery Assessment:...
Xu Cui
7 sec read

Calculate phase difference between two general signals (e.g. HbO…

In a recent fNIRS journal club (vedio recorded here), Dr. Tong talked about their work on the phase difference between oxy and deoxy Hb,...
Xu Cui
1 min read

2 Replies to “brain images: Change data type of brain image”

  1. If I’m not mistaken that’s only true for SPM2. For SPM5 and SPM8 the field ‘dim’ has only three entries and the first entry of the field ‘dt’ carries the information about the data type.

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading