-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessBKGandFLATnew.m
More file actions
185 lines (150 loc) · 4.8 KB
/
preprocessBKGandFLATnew.m
File metadata and controls
185 lines (150 loc) · 4.8 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%% fullbkg
function preprocessBKGandFLATnew(A,B)
% A = 'D:\Frick\';
% B = '2015_12_15 smad3g smFISH';
C = B;
E={B}; %beginning of file name for saving
F = {'_back_c1_t','_back_c2_t','_back_c3_t'};
FF = {'*c1_*.tif','*c2_*.tif','*c3_*.tif'};
% BACKGROUND = [13 14 15 16 17];
% BACKGROUND = [28 29 30 31];
% BACKGROUND = [7:11];
BACKGROUND = [25:29];
BACKGROUND = [1:12];
BACKdir = strcat(A,B,'\back');mkdir (BACKdir);
DIRone = strcat(A,B,'\',C);
cd(DIRone);
dirlist = dir('*.tif');
[~,~,~,ScenesListed] = regexp([dirlist.name],'s[0-9]+');
sceneList = unique(ScenesListed);
[~,~,~,timeFrameList] = regexp([dirlist.name],'t[0-9]+');
timeList = unique(timeFrameList);
[~,~,~,channelsListed] = regexp([dirlist.name],'c[0-9]+');
channelList = unique(channelsListed);
cd ..
mkdir(strcat(A,B,'\flatfield_corrected'));
cd (strcat(A,B,'\flatfield_corrected'));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%make folders for each scene
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for scenedir = sceneList
scene = scenedir{1};
% sceneN = str2num(scene(2:end));
% scenenum = scenestring(sceneN);
scenefile{1} = strcat(E{1},'_scene_',scene);
mkdir(scenefile{1});
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for DIRflats = {DIRone} %choose directory (this is a remant of splitz)
DIRflat = char(DIRflats);
DIRflatcomp = DIRflat(end-5:end);
DIRonecomp = DIRone(end-5:end);
cd (DIRflat)
for channel = channelList %cycle through one channel at a time
filelist = dir(strcat('*',char(channel),'*.tif'));
cfile = {filelist.name};
% for j = 1:length(cfile) %load image and determine scene and timepoint and channel
for j = 1:length(cfile) %load image and determine scene and timepoint and channel
filename = char(cfile(j));
img = imread(filename);
[a,b] = regexp(filename,'s[0-9]+'); %determine scene
scene = filename(a:b);
[c,d] = regexp(filename,'t[0-9]+'); %determine timepoint
if ~isempty(c)
tpoint = filename(c:d);
tpoints = tpoint;
else
tpoint='t00';
tpoints = '*';
end
[e,f] = regexp(filename,'c[0-9]+'); %determine channel
chan = filename(e:f);
bkimg = medianBKG(BACKGROUND,tpoints,chan); %load background images and compile into one median image
bkShape = reshape(bkimg,[1 size(bkimg,2).*size(bkimg,1)]);
bkSort = sort(bkShape(~isnan(bkShape)));
normalizedBkgimg = (double(bkimg)./mean([bkSort(round(length(bkSort).*0.9999)) bkSort(round(length(bkSort).*0.99999))]));
flat = uint16(double(img)./normalizedBkgimg); %flatten the experimental image with the background image
savename = strcat(E,'_flat_',scene,'_',tpoint,'_',chan,'.tif');
SAVdir = strcat(A,B,'\flatfield_corrected\',E{1},'_scene_',scene);
savethatimage(savename,SAVdir,flat,DIRflat,j);
end
end
end
% lineageyo(A,B);
% cd('D:\Users\zeiss\Documents\MATLAB')
% % bleachcorrection(A,B)
% bleachcorrectionNew(A,B)
% cd('D:\Users\zeiss\Documents\MATLAB')
% toughsegmentationforstacks(A,B)
end
function bkimg = medianBKG(BACKGROUND,tpoints,chan)
bkimgs = zeros(512,512,length(BACKGROUND));
i = 1;
for scenenumber = BACKGROUND
scene = scenestring(scenenumber);
files = strcat('*',scene,'*',tpoints,'*',chan,'*');
filelist = dir(files); cfile = {filelist.name}; filename = char(cfile);
bkimgs(:,:,i) = imread(filename);
i=i+1;
end
bkimg = median(bkimgs,3);
end
function scene = scenestring(scenenumber)
scene = char('s00');
reg = num2str(scenenumber);
c = size(reg,2);
for b = 1:c
scene(3+1-b) = reg(c+1-b);
end
end
function tpoint = timestring(time)
tpoint = char('t00');
reg = num2str(time);
c = size(reg,2);
for b = 1:c
tpoint(3+1-b) = reg(c+1-b);
end
end
function savethatimage(savename,SAVdir,flat,DIRone,j)
disp(strcat(savename,'...',num2str(j)));
cd (SAVdir);
imwrite(flat,char(savename),'tiff');
cd (DIRone);
end
function lineageyo(A,B)
%%
F = {'_c1_ORG.tif','_c2_ORG.tif','_c3_ORG.tif'};
FF = {'*c1_*.tif','*c2_*.tif','*c3_*.tif'};
cd (strcat(A,B));
cd ('flatfield_corrected')
%%
folderlist = dir('*_s*');
folderlist.name;
for folder = {folderlist.name}
cd(folder{1})
mkdir('c1_flat')
mkdir('c2_flat')
mkdir('c3_flat')
mkdir('tiffs');
filelist = dir('*c1*.tif');
for cfile={filelist.name}
filepath = which(cfile{1});
disp(filepath);
movefile(filepath,'c1_flat')
end
filelist = dir('*c2*.tif');
for cfile={filelist.name}
filepath = which(cfile{1});
disp(filepath);
movefile(filepath,'c2_flat')
end
filelist = dir('*c3*.tif');
for cfile={filelist.name}
filepath = which(cfile{1});
disp(filepath);
movefile(filepath,'c3_flat')
end
cd ..
end
end