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通知2024/05/11, 10am 雷心博士

机器人通常以合作者的身份出现,以礼貌、鼓励、友好的方式与人类互动,但如果有一个竞争导向的机器人出现会如何?人们更喜欢与合作导向的机器人互动,还是更愿意通过竞争来激发自身动力呢?当我们与机器人合作或竞争
Wanling Zhu
13 sec read

第五十期fNIRS Journal Club视频 王一晖

Youtube: https://youtu.be/a2QlCFZUytA优酷:https://v.youku.com/v_show/id_XNjM3MjMyNjUxMg==.html 早期的 STE
Wanling Zhu
13 sec read

第五十期fNIRS Journal Club通知2024/03/30, 10am 王一晖

早期的 STEM 教育对于以后的学习至关重要。现有研究尚未就STEM教学法达成共识,学生先验知识对基于故事的STEM教学法的影响还有待探讨。来自澳门大学张娟教授团队的王一晖将会分享基于fNIRS超扫描
Wanling Zhu
9 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 to Boureghda Mohammed Cancel reply

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