|
| 1 | +% (C) Copyright 2020 CPP BIDS SPM-pipeline developers |
| 2 | + |
| 3 | +%% examples to create ROIs and extract data |
| 4 | +% |
| 5 | +% ROI: use the probability map for visual motion from Neurosynth |
| 6 | +% link: https://neurosynth.org/analyses/terms/visual%20motion/ |
| 7 | +% |
| 8 | +% Data: tmap of Listening > Baseline from the MoAE demo |
| 9 | + |
| 10 | +clear; |
| 11 | +clc; |
| 12 | + |
| 13 | +%% ASSUMPTION |
| 14 | +% |
| 15 | +% This assumes that the 2 immages are in the same space (MNI, individual) |
| 16 | +% but they might not necessarily have the same resolution. |
| 17 | +% |
| 18 | +% In SPM lingo this means they are coregistered but not necessarily resliced. |
| 19 | +% |
| 20 | + |
| 21 | +%% IMPORTANT: for saving ROIs |
| 22 | +% |
| 23 | +% To save the ROIs, MarsBar must be installed: http://marsbar.sourceforge.net/ |
| 24 | +% - either in the "spm12/toolbox" folder |
| 25 | +% - in the "cpp_spm/lib" folder |
| 26 | +% |
| 27 | +% https://sourceforge.net/projects/marsbar/files/marsbar/0.44/marsbar-0.44.zip/download |
| 28 | +% |
| 29 | +% cp -r /home/myhome/marsbar-0.44/* \ |
| 30 | +% /usr/local/spm/spm12/toolbox/marsbar |
| 31 | +% |
| 32 | +% If you want to save the ROI you are creating, you must make sure that the ROI |
| 33 | +% image you are using DOES have the same resolution as the image you will |
| 34 | +% sample. |
| 35 | +% |
| 36 | +% You can use the resliceRoiImages for that. |
| 37 | + |
| 38 | +%% |
| 39 | +probabilityMap = fullfile(pwd, 'inputs', 'visual motion_association-test_z_FDR_0.01.nii'); |
| 40 | +dataImage = fullfile(pwd, 'inputs', 'TStatistic.nii'); |
| 41 | + |
| 42 | +opt.unzip.do = true; |
| 43 | +opt.save.roi = true; |
| 44 | +if opt.save.roi |
| 45 | + opt.reslice.do = true; |
| 46 | +else |
| 47 | + opt.reslice.do = false; |
| 48 | +end |
| 49 | + |
| 50 | +[roiName, probabilityMap] = preprareDataAndROI(opt, dataImage, probabilityMap); |
| 51 | +data_mask = getDataFromMask(dataImage, roiName); |
| 52 | +data_sphere = getDataFromSphere(opt, dataImage); |
| 53 | +data_intersection = getDataFromIntersection(opt, dataImage, roiName); |
| 54 | +data_expand = getDataFromExpansion(opt, dataImage, roiName); |
| 55 | + |
| 56 | +%% Mini functions |
| 57 | + |
| 58 | +% only to show how each case works |
| 59 | + |
| 60 | +function data_mask = getDataFromMask(dataImage, roiName) |
| 61 | + |
| 62 | + data_mask = spm_summarise(dataImage, roiName); |
| 63 | + |
| 64 | +end |
| 65 | + |
| 66 | +function data_sphere = getDataFromSphere(opt, dataImage) |
| 67 | + |
| 68 | + % X Y Z coordinates of right V5 in millimeters |
| 69 | + location = [44 -67 0]; |
| 70 | + |
| 71 | + % radius in millimeters |
| 72 | + radius = 5; |
| 73 | + |
| 74 | + sphere.location = location; |
| 75 | + sphere.radius = radius; |
| 76 | + |
| 77 | + mask = createRoi('sphere', sphere, dataImage, opt.save.roi); |
| 78 | + |
| 79 | + data_sphere = spm_summarise(dataImage, mask); |
| 80 | + |
| 81 | + % equivalent to |
| 82 | + % b = spm_summarise(dataImage, ... |
| 83 | + % struct( ... |
| 84 | + % 'def', 'sphere', ... |
| 85 | + % 'spec', radius, ... |
| 86 | + % 'xyz', location')); |
| 87 | + |
| 88 | +end |
| 89 | + |
| 90 | +function data_intersection = getDataFromIntersection(opt, dataImage, roiName) |
| 91 | + |
| 92 | + % X Y Z coordinates of right V5 in millimeters |
| 93 | + location = [44 -67 0]; |
| 94 | + |
| 95 | + sphere.location = location; |
| 96 | + sphere.radius = 5; |
| 97 | + |
| 98 | + mask = createRoi('intersection', roiName, sphere, dataImage, opt.save.roi); |
| 99 | + |
| 100 | + data_intersection = spm_summarise(dataImage, mask.roi.XYZmm); |
| 101 | + |
| 102 | +end |
| 103 | + |
| 104 | +function data_expand = getDataFromExpansion(opt, dataImage, roiName) |
| 105 | + |
| 106 | + % X Y Z coordinates of right V5 in millimeters |
| 107 | + location = [44 -67 0]; |
| 108 | + |
| 109 | + sphere.location = location; |
| 110 | + sphere.radius = 1; % starting radius |
| 111 | + sphere.maxNbVoxels = 50; |
| 112 | + |
| 113 | + mask = createRoi('expand', roiName, sphere, dataImage, opt.save.roi); |
| 114 | + |
| 115 | + data_expand = spm_summarise(dataImage, mask.roi.XYZmm); |
| 116 | + |
| 117 | +end |
| 118 | + |
| 119 | +%% HELPER FUNCTION |
| 120 | + |
| 121 | +function [roiName, probabilityMap] = preprareDataAndROI(opt, dataImage, probabilityMap) |
| 122 | + |
| 123 | + if opt.unzip.do |
| 124 | + gunzip(fullfile('inputs', '*.gz')); |
| 125 | + end |
| 126 | + |
| 127 | + if opt.reslice.do |
| 128 | + % If needed reslice probability map to have same resolution as the data image |
| 129 | + % |
| 130 | + % resliceImg won't do anything if the 2 images have the same resolution |
| 131 | + % |
| 132 | + % if you read the data with spm_summarise, |
| 133 | + % then the 2 images do not need the same resolution. |
| 134 | + probabilityMap = resliceRoiImages(dataImage, probabilityMap); |
| 135 | + end |
| 136 | + |
| 137 | + % Threshold probability map into a binary mask |
| 138 | + % to keep only values above a certain threshold |
| 139 | + threshold = 10; |
| 140 | + roiName = thresholdToMask(probabilityMap, threshold); |
| 141 | + |
| 142 | +end |
0 commit comments