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通知2025/4/12, 10am 冯小丹

无论是对人类个体的认知能力发展还是对整个社会的文明演进来说,课堂教学都发挥着不可替代的独特作用。正如著名教育思想家夸美纽斯 (John Amos Comenius) 所言,“年轻人最好还是在班级里一起
Wanling Zhu
10 sec read

第六十期fNIRS Journal Club视频 邹立业教授团队

Youtube: https://youtu.be/8NG3pwUF9sM 优酷:https://v.youku.com/video?vid=XNjQ2ODE3NzA4NA%3D%3D 长时间久坐行为
Wanling Zhu
19 sec read

第六十期fNIRS Journal Club通知2025/3/8, 10am 邹立业教授团队

长时间久坐行为往往会引起脑血流供应不足,进而导致注意力下降及执行功能表现减弱,并影响人脑学习的信息加工过程。以往研究表明体育活动对执行功能表现具有积极作用。然而,关于在久坐期间进行短时有氧运动干预是否
Wanling Zhu
14 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 *