forked from evodevosys/AroSpotFindingSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrectBleachAndFilter.m
executable file
·41 lines (36 loc) · 1.21 KB
/
correctBleachAndFilter.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
function [segStacks,bleachFactors]=correctBleachAndFilter(segStacks,varargin)
% ============================================================
% Name: correctBleachAndFilter.m
% Version: 2.0, 3rd July 2012
% Author: Allison Wu, Scott Rifkin
% * Build from correctForBleach
% * Correct for bleach with respect to individual worms in individual channel.
% * Varagin{1}: [0,1] whether to apply laplacian filter, 0 by default.
% =============================================================
% Find out the size of the segmented stacks
h=size(segStacks{1},3); % Assuming all stacks are the same height
%% Slice as reference
wormNum=length(segStacks);
iRefSlice=max(1,floor(h/2));
bleachFactors=zeros(h,wormNum);
if isempty(varargin)
toFilter=0;
else
toFilter=varargin{1};
end
for wi=1:wormNum
stack=segStacks{wi};
refSlice=stack(:,:,iRefSlice);
medRefSlice=median(refSlice(refSlice(:)>0));
for zi=1:h
slice=stack(:,:,zi);
medSlice=median(slice(slice(:)>0));
bleachFactors(zi,wi)=medSlice/medRefSlice;
stack(:,:,zi)=stack(:,:,zi)/bleachFactors(zi,wi);
if toFilter==1
stack(:,:,zi)=laplaceembryos(stack(:,:,zi));
end
end
segStack{wi}=stack;
end
end