-
Notifications
You must be signed in to change notification settings - Fork 0
/
SM_BatchDff.m
140 lines (96 loc) · 2.82 KB
/
SM_BatchDff.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function SM_BatchDff(DIR, varargin)
%run thorough directory and make DfF movies in AVI format
% WALIII
% 09.05.15
mat_dir='DFF_MOVIES';
counter = 1;
if exist(mat_dir,'dir') rmdir(mat_dir,'s'); end
mkdir(mat_dir);
outlier_flag=0;
if nargin<1 | isempty(DIR), DIR=pwd; end
mov_listing=dir(fullfile(DIR,'*.mat'));
mov_listing={mov_listing(:).name};
filenames=mov_listing;
disp('Creating Dff movies');
[nblanks formatstring]=fb_progressbar(100);
fprintf(1,['Progress: ' blanks(nblanks)]);
for i=1:length(mov_listing)
[path,file,ext]=fileparts(filenames{i});
fprintf(1,formatstring,round((i/length(mov_listing))*100));
load(fullfile(DIR,mov_listing{i}),'video');
%create DFF
figure, set(gcf, 'Color','white')
axis tight
set(gca, 'nextplot','replacechildren', 'Visible','off');
%# create AVI object
save_filename=[ fullfile(mat_dir,file) ];
vidObj = VideoWriter(save_filename);
vidObj.Quality = 30;
vidObj.FrameRate = 30;
open(vidObj);
colormap(bone);
mov_data = video.frames;
%%%%
for i=1:(length(mov_data))
% mov_data3 = single(rgb2gray(mov_data(i).cdata));
% mov_data4 = single(rgb2gray(mov_data(i+1).cdata));
% %mov_data5 = single(rgb2gray(mov_data(i+2).cdata));
mov_data2(:,:,i) = uint8(mov_data(i).cdata/256);
end
test2=(mov_data2);
% test=imresize((test),1);
%
% h=fspecial('disk',1);
% bground=imfilter(test,h);
% % bground=smooth3(bground,[1 1 5]);
% test=test-bground;
%
%
% h=fspecial('disk',1);
% test2=imfilter(test,h);
%%%%%
LinKat = cat(1,test2(:,1,10)); % initilaize linkat
for i = 2:size(test2,2)
Lin = cat(1,test2(:,i,10));
LinKat = cat(1,LinKat,Lin);
end
H = prctile(LinKat,95)+10 % take the pixel value equal to the 70th percentile value
L = prctile(LinKat,5)
test2=imresize(test2,1);
[optimizer, metric] = imregconfig('multimodal');
%# create movie
for i=1:(length(mov_data)-2);
%test3(:,:,i) = imregister(test2(:,:,i),test2(:,:,1),'rigid',optimizer,metric);
image(test2(:,:,i),'CDataMapping','scaled');
caxis([double(L),double(H)])%caxis([0,70]) % change caxis
writeVideo(vidObj, getframe(gca));
end
close(gcf)
%# save as AVI file, and open it using system video player
close(vidObj);
FrameInfo = max(test2,[],3);
%figure();
colormap(bone)
imagesc(FrameInfo);
%set(gca,'ydir','normal'); % Otherwise the y-axis would be flipped
X = mat2gray(FrameInfo);
X = im2uint8(X);
imwrite(X,save_filename,'png')
TotalX(:,:,counter) = X;
TotalX2{counter} = X;
counter = counter+1;
end
fprintf(1,'\n');
%%
% [optimizer, metric] = imregconfig('multimodal');
% for g = 1:size(TotalX,3)
% tiledImage(:,:,g) = imregister(TotalX(:,:,g), TotalX(:,:,1),'rigid',optimizer, metric);
% end
%
FrameInfo2 = max(TotalX,[],3);
imwrite(FrameInfo2,'Dff_composite','png')
% Test = TotalX2;
% %mov_data = video.frames;
% im_resize = 1;
%
% save(save_filename,'Test','mov_data','im_resize','-v7.3')