-
Notifications
You must be signed in to change notification settings - Fork 7
/
magia_identify_bad_frames.m
51 lines (38 loc) · 1.22 KB
/
magia_identify_bad_frames.m
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
function bad_frames = magia_identify_bad_frames(filename)
[~,n] = fileparts(filename);
fprintf('Identifying bad frames for %s...',n);
V = spm_vol(filename);
img = spm_read_vols(V);
nx = size(img,1);
ny = size(img,2);
N = size(img,4);
bad_frames = false(N,1);
for i = 1:N
mean_axial_slice = mean(img(:,:,:,i),3);
xmean = mean(mean_axial_slice,2)';
ymean = mean(mean_axial_slice,1);
% figure(1); clf; imagesc(mean_axial_slice);
% figure(2); clf; subplot(2,1,1); bar(xmean); subplot(2,1,2); bar(ymean);
xpos = xmean > 0;
ypos = ymean > 0;
max_consecutive_pos_x = magia_max_consecutive_values(xpos,nx);
max_consecutive_pos_y = magia_max_consecutive_values(ypos,ny);
prop_pos_x = max_consecutive_pos_x/nx;
prop_pos_y = max_consecutive_pos_y/ny;
if(prop_pos_x < 0.3 || prop_pos_y < 0.3)
bad_frames(i) = true;
end
end
fprintf(' Done.\n');
if(~any(bad_frames))
fprintf('No bad frames detected for %s.\n',n);
else
frame_idx = find(bad_frames);
M = length(frame_idx);
msg = sprintf('The following frames were identified as bad for %s:',n);
for i = 1:M
msg = sprintf('%s %.0f',msg,frame_idx(i));
end
fprintf('%s\n',msg);
end
end