-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautofocusWithRotAndTrans.m
More file actions
49 lines (36 loc) · 1.33 KB
/
Copy pathautofocusWithRotAndTrans.m
File metadata and controls
49 lines (36 loc) · 1.33 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
function [bestTranslations,metric] = autofocusWithRotAndTrans(sinogram, ...
maxX, dx, maxY, dy, maxRot, dr, nRows, nCols, pixSize, detSize, ...
thetas, method)
[nThetas,nDetectors] = size(sinogram);
x = [-maxX:dx:maxX];
y = [-maxY:dy:maxY];
metric = zeros(numel(x),numel(y));
translations = zeros( nThetas, 2 );
R = makeRadonMatrix( nCols, nRows, pixSize, nDetectors, ...
detSize, thetas);
nR = numel(r);
for k = 1:nR
maxRotation = r(k) * pi/180;
rotations = linspace(0,maxRotation,nThetas);
nX = numel(x);
for i = 1:nX
disp(['Working on ', num2str(i), ' of ', num2str(nX)]);
maxHorizontalShift = x(i); % in meters
translations(:,2) = linspace(0,maxHorizontalShift,nThetas);
for j = 1:numel(y)
maxVerticalShift = y(j); % in meters
translations(:,1) = linspace(0,maxVerticalShift,nThetas);
recon = ctCorrectForRotAndTrans( sinogram, nDetectors, ...
detSize, thetas, rotations, translations, nCols, nRows, ...
pixSize, 'method', method, 'radonMatrix', R );
metric(i,j) = normgrad(recon);
end
end
end
[row,col] = find( metric==max(metric(:)) );
bestTranslations = [y(col),x(row)];
end
function [out] = normgrad(img)
imgv = img(:);
out = sum((abs(conv2([1;-1],imgv))./sum(abs(conv2([1;-1],imgv)))).^2);
end