|
1 | | -function roiImage = extractRoiFromAtlas(roiDir, atlas, roiName, hemisphere) |
| 1 | +function roiImage = extractRoiFromAtlas(outputDir, atlasName, roiName, hemisphere) |
| 2 | + % |
| 3 | + % Outputs a ROI image and side car json for a given atlas, roi name (as |
| 4 | + % defined in the look up table of that atlas) and a hemisphere |
| 5 | + % |
| 6 | + % USAGE:: |
| 7 | + % |
| 8 | + % roiImage = extractRoiFromAtlas(outputDir, atlasName, roiName, hemisphere) |
| 9 | + % |
| 10 | + % :param outputDir: |
| 11 | + % :param atlasName: ``wang``, ``neuromorphometrics`` |
| 12 | + % :param roiName: run ``getLookUpTable(atlasName)`` to get a list of ROI names to choose from |
| 13 | + % :param hemisphere: ``L`` or ``R`` |
| 14 | + % :type outputDir: string |
| 15 | + % :type atlasName: string |
| 16 | + % :type roiName: string |
| 17 | + % :type hemisphere: string |
2 | 18 | % |
3 | 19 | % (C) Copyright 2021 CPP ROI developers |
4 | 20 |
|
5 | | - if strcmp(atlas, 'wang') |
| 21 | + [atlasFile, lut] = getAtlasAndLut(atlasName); |
6 | 22 |
|
7 | | - [maxProbaFiles, roiLabels] = getRetinoProbaAtlas(); |
| 23 | + if strcmp(atlasName, 'wang') |
8 | 24 |
|
9 | 25 | if strcmp(hemisphere, 'L') |
10 | | - sourceImage = maxProbaFiles(1, :); |
| 26 | + atlasFile = atlasFile(1, :); |
11 | 27 | else |
12 | | - sourceImage = maxProbaFiles(2, :); |
| 28 | + atlasFile = atlasFile(2, :); |
13 | 29 | end |
14 | 30 |
|
15 | | - elseif strcmp(atlas, 'neuromorphometrics') |
| 31 | + roiIdx = strcmp(roiName, lut.ROI); |
16 | 32 |
|
17 | | - sourceImage = fullfile(returnAtlasDir(), 'space-IXI549Space_desc-neuromorphometrics_dseg.nii'); |
| 33 | + elseif strcmp(atlasName, 'neuromorphometrics') |
18 | 34 |
|
19 | | - roiLabels = getRoiLabelLookUpTable(atlas); |
| 35 | + roiName = regexprep(roiName, '(Left )|(Right )', ''); |
| 36 | + |
| 37 | + if strcmp(hemisphere, 'L') |
| 38 | + prefix = 'Left '; |
| 39 | + elseif strcmp(hemisphere, 'L') |
| 40 | + prefix = 'Right '; |
| 41 | + end |
| 42 | + |
| 43 | + roiIdx = strcmp([prefix roiName], lut.ROI); |
20 | 44 |
|
21 | 45 | end |
22 | 46 |
|
23 | | - roiIdx = strcmp(roiName, roiLabels.ROI); |
24 | | - label = roiLabels.label(roiIdx); |
| 47 | + % create ROI |
| 48 | + if isempty(roiIdx) || ~any(roiIdx) |
| 49 | + disp(lut.ROI); |
| 50 | + error('No ROI named %s for atlas %s. See list of available ROIs above', ... |
| 51 | + roiName, atlasName); |
| 52 | + end |
| 53 | + label = lut.label(roiIdx); |
25 | 54 |
|
26 | | - labelStruct = struct('ROI', [hemisphere roiName], ... |
| 55 | + labelStruct = struct('ROI', roiName, ... |
27 | 56 | 'label', label); |
28 | 57 |
|
29 | | - roiImage = extractRoiByLabel(sourceImage, labelStruct); |
| 58 | + roiImage = extractRoiByLabel(atlasFile, labelStruct); |
30 | 59 |
|
| 60 | + % rename file |
31 | 61 | entities = struct('space', 'MNI', ... |
32 | 62 | 'hemi', hemisphere, ... |
33 | 63 | 'label', roiName, ... |
34 | | - 'desc', atlas); |
| 64 | + 'desc', atlasName); |
35 | 65 | nameStructure = struct('entities', entities, ... |
36 | 66 | 'suffix', 'mask', ... |
37 | 67 | 'ext', '.nii'); |
38 | | - |
39 | 68 | nameStructure.use_schema = false; |
40 | | - |
41 | 69 | newName = bids.create_filename(nameStructure); |
42 | 70 |
|
43 | | - movefile(roiImage, fullfile(roiDir, newName)); |
44 | | - |
45 | | - roiImage = fullfile(roiDir, newName); |
| 71 | + movefile(roiImage, fullfile(outputDir, newName)); |
46 | 72 |
|
| 73 | + % create side car json |
| 74 | + roiImage = fullfile(outputDir, newName); |
47 | 75 | json = bids.derivatives_json(roiImage); |
48 | 76 | bids.util.jsonencode(json.filename, json.content); |
| 77 | + |
49 | 78 | end |
0 commit comments