-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampEnScript.m
More file actions
53 lines (48 loc) · 1.9 KB
/
SampEnScript.m
File metadata and controls
53 lines (48 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% This Script will run on the contents inside the specified folder,
%converting each nifti file, and then running the sampEn script on the file.
%This script is for my (Hisham's) personal use, if you need to adapt it to
%your own needs, send me a message so i can explain how it works and where
%it needs to go if you cant figure it out.
echo on;
addpath('/keilholz-lab/hisham/tools/nifti_20140122');
addpath('/keilholz-lab/hisham/sample_entropy_project/code');
%First, convert .nii.gz files to .nii fslchfiletype NIFTI (decompressing seems to break due to
%file size so this is the best workaround i have found) Make sure you have
%navigated to the folder you're running the script on in the command line
%before you open matlab.
%Creates cell array of file names
directory = dir;
filenames = {directory(:).name};
filenames = regexp(filenames,'.*\.nii','match');
filenames(cellfun('isempty',filenames)) = [];
fileNum = size(filenames,2);
niiImages = cell(fileNum,1);
entropyImages = cell(fileNum,1);
%loads nii files into separate cell array
for k = 1:fileNum
echo on;
file = filenames{k};
file = file{1};
niiImages{k} = load_nii(file);
niiImages{k} = niiImages{k}.img;
end
%calculates entropy images, saves photo and individual .mat file
for k = 1:size(niiImages,1)
entropyImages{k} = entropyCalc(niiImages{k});
entropyImages{k} = rot90(permute(entropyImages{k},[1 3 2]));
flattenedImage = imFlat(entropyImages{k});
imagesc(flattenedImage);
colormap jet;
colorbar;
fileName = filenames{k};
fileName = fileName{1};
fileHead = strtok(fileName,'.');
filenamePNG = [fileHead '_EnImage.png'];
filenameMAT = [fileHead '_EnImage.mat'];
saveas(gcf,filenamePNG);
toSave = entropyImages{k};
save(filenameMAT,'toSave');
end
%additionally, save all entropyimages to one single .mat, for use in
%calculating average, once this is done.
save('allImages.mat','entropyImages');