forked from tes24/CNS-Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign_example_v1.m
More file actions
58 lines (39 loc) · 2 KB
/
align_example_v1.m
File metadata and controls
58 lines (39 loc) · 2 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
% Written by Sham Tlili and edited by Timothy Saunders
% Code for aligning data of CNS from SPIM data to detwich embryo
% Reads data in "images_original"
% tstart= first time point to be aligned
% tend = final time point to be aligned
% dbin = binning of data
% optimizer allows control of iterations, step lengths
addpath('./Useful Functions/')
tic
folder_image = './images_original/'; % Input data
folder_results = './images_aligned/'; % Output data
tstart = 1; % Start time
tend = 2; % End time
dbin = 8; % Binning size
for time = tstart+1:1:tend
disp(['On time ',num2str(time), ' of ', num2str(tend)])
% Load data
name_movie1 = [folder_results 'image_' num2str(time-1) '.tif'];
stack1 = double(readTIFstack(name_movie1));
name_movie2 = [folder_image 'image_' num2str(time) '.tif'];
stack2 = double(readTIFstack(name_movie2));
[sy,sx,sz] = size(stack1);
[y_pixels, x_pixels, z_pixels] = ndgrid(1:1:sy,1:1:sx,1:1:sz);
[y_bin, x_bin, z_bin] = ndgrid(1:dbin:sy,1:dbin:sx,1:dbin:sz);
bined_stack1 = interp3(stack1,x_bin,y_bin,z_bin);
bined_stack2 = interp3(stack2,x_bin,y_bin,z_bin);
[optimizer, metric] = imregconfig('monomodal');
optimizer.MaximumIterations = 2000;
% optimizer.MinimumStepLength = 0.05; % Can be adjusted if needed
% optimizer.MaximumStepLength = 0.1; % Can be adjusted if needed
tform = imregtform(bined_stack2, bined_stack1, 'rigid', optimizer, metric);
tform_final = tform;
tform_final.T(4,1:3) = dbin*tform_final.T(4,1:3);
slice_interp_turn = imwarp(stack2,tform_final,'OutputView',imref3d(size(stack2)));
name_align = [folder_results 'image_' num2str(time) '.tif'];
stack_turned = uint16(slice_interp_turn);
writeTIFstack(stack_turned, name_align, 2^31)
end
toc