Convert images to matrix

21 sec read

Quite often you need to convert an image (or multiple images) to a MatLab matrix for further analysis and visualization (e.g. extracting time series, multivariate pattern analysis, etc). SPM provides handy functions for this:

P = spm_select; % select 1 or more images
V = spm_vol(P);
M = spm_read_vols(V);

The dimension of M is 3D or 4D depending on how many images you selected. The 1st 3 dimensions are spatial and the last one is temporal.

If you want to save a matrix to a image file, use

V.fname = 'b.img';%
spm_write_vol(V, M);


Want to receive new post notification? 有新文章通知我

第四十一期fNIRS Journal Club通知2023/6/3, 10am 徐四华教授

人际关系和群体中个体的特征是否会影响正常交互中面临不确定性时的群体决策?来自上海外国语大学的徐四华教授将分享如何利用近红外成像技术揭示在不同人际关系和人际取向中的群体决策倾向的神经机制。 时间:北京时
Xu Cui
9 sec read

第四十期fNIRS Journal 视频 张丹丹教授

Youtube: 个人简
Xu Cui
6 sec read

第四十期fNIRS Journal Club通知2023/5/6, 10am 张丹丹教授

人类新生儿对语言具有高度的敏感性,刚出生的新生儿能加工各种复杂的语音刺激。来自四川师范大学的张丹丹教授将分享如何利用近红外脑成像技术研究新生儿对语音的加工及学习。欢迎大家踊跃参与和讨论。 时间:北京时
Xu Cui
2 sec read

3 Replies to “Convert images to matrix”

  1. sir,
    i need to generate .mat file for ORL database(say). how to do it?also can i use the same .mat file in regression/classification?how to split database into predictor and response arrays (X & Y) for regression/classification.
    please provide suitable matlab functions.
    thank you

Leave a Reply

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