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);



写作助手,把中式英语变成专业英文


AI writing papers with real references


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

第七十四期fNIRS Journal Club视频 曾令伟博士

Youtube: https://youtu.be/WSh0fmADeZw 优酷:https://v.youku.com/v_show/id_XNjU2MzcyOTU3Ng==.html 认知状态解码
Wanling Zhu
21 sec read

第七十四期fNIRS Journal Club通知2026/9/5, 10am 曾令伟博士

认知状态解码是脑机接口与神经调控研究的重要基础,但如何利用fNIRS实现有效解码并进一步用于个体化认知干预仍有待探索。来自空军军医大学的曾令伟博士将介绍他们围绕fNIRS认知状态解码与闭环神经调控开展
Wanling Zhu
16 sec read

第七十三期fNIRS Journal Club视频 梁正博士 赵庆柏课题组

Youtube: https://youtu.be/5r8OR9rmDxo 优酷:https://v.youku.com/v_show/id_XNjU0ODIxNDEwNA==.html 创造性思维是
Wanling Zhu
20 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 *