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/07/27, 10am 黄鑫

电子烟作为一种新型的尼古丁输送装置,常以安全健康、有助于戒烟的形象出现在公众视野中,使得大批消费者转而投入到此类产品的怀抱中。然而,相关研究却仍存较大短板,深入了解电子烟对行为与脑功能活动的影响将更好
Wanling Zhu
10 sec read

第五十三期fNIRS Journal Club视频 李洪

Youtube: https://youtu.be/czyJTrXhees优酷:https://v.youku.com/v_show/id_XNjQwNjc5OTk0OA==.html 个体在处理不同
Wanling Zhu
12 sec read

第五十三期fNIRS Journal Club通知2024/06/22, 10am 李洪

个体在处理不同记忆负荷信息时会表现出一定的行为差异。作为一项新兴指标,瞬时脑信号变异性能够揭示个体内部因任务需求不断变化而进行的神经资源分配,从而为了解大脑如何适应和处理不同复杂程度的信息提供了新的见
Wanling Zhu
8 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 *