Note
Go to the end to download the full example code.
Shifted detector on a short scan#
Why Wang weights are skipped on short scans, shown on a uniform cylinder.
Source: Python/demos/d26_ShortScanWangWeights.py · MATLAB/Demos/d26_ShortScanWangWeights.m
MATLAB version of this demo
%% Demo 26: Wang detector-offset weights on a short scan
%
% Wang weighting compensates a displaced detector on a FULL circular scan: it
% ramps one side of the detector down and relies on the opposing (beta + pi)
% views to bring the coverage back to uniform. On a short scan those opposing
% views do not exist, so the ramp survives into the reconstruction as a
% one-sided shading (a "teardrop"). Any non-zero offDetector switches the
% weights on - a sub-pixel calibrated offset is enough - so a short scan with a
% calibrated geometry was silently shaded.
%
% FDK now skips the Wang weights when the angles do not cover a full circle
% (the same test it already uses to decide Parker weighting). This demo
% reconstructs a uniform cylinder from a 200-degree scan three ways and prints
% the left/right interior ratio:
%
% centred detector -> balanced (reference)
% 0.1 mm offset, Wang applied by hand -> the teardrop (what happened before)
% 0.1 mm offset, FDK default -> Wang skipped, balanced again
%
% Wang weights are still applied on full scans, where they belong.
%--------------------------------------------------------------------------
% This file is part of the TIGRE Toolbox
%
% Copyright (c) 2015, University of Bath and
% CERN-European Organization for Nuclear Research
% All rights reserved.
%
% License: Open Source under BSD.
% See the full license at
% https://github.com/CERN/TIGRE/blob/master/LICENSE
%
% Contact: tigre.toolbox@gmail.com
% Codes: https://github.com/CERN/TIGRE/
%--------------------------------------------------------------------------
clear; close all;
%% Geometry: default, 64^3 image
geo = defaultGeometry('nVoxel', [64; 64; 64]);
geo.sVoxel = [64; 64; 64];
geo.dVoxel = geo.sVoxel ./ geo.nVoxel;
%% Uniform cylinder, mu = 0.02
[xx, yy, zz] = meshgrid(1:64, 1:64, 1:64);
mu = 0.02;
phantom = single(((xx - 32.5).^2 + (yy - 32.5).^2 <= 20^2) * mu);
core = (xx - 32.5).^2 + (yy - 32.5).^2 <= 14^2;
%% Short scan: 200 degrees
angles = linspace(0, deg2rad(200), 200);
proj = Ax(phantom, geo, angles);
lr = @(vol) [mean(vol(core & xx <= 32 & zz >= 17 & zz <= 48)), ...
mean(vol(core & xx > 32 & zz >= 17 & zz <= 48))];
%% 1. centred detector (reference)
vol_ref = FDK(proj, geo, angles);
r = lr(vol_ref);
fprintf('centred detector : left %.5f right %.5f ratio %.3f\n', r(1), r(2), r(1) / r(2));
%% 2. 0.1 mm offset, Wang weights applied regardless of the arc (the old behaviour)
geo_off = geo;
geo_off.offDetector = [0.1; 0]; % u offset, a fraction of a pixel
proj_w = proj .* redundancy_weighting(geo_off);
vol_wang = FDK(proj_w, geo_off, angles, 'wang', false);
r = lr(vol_wang);
fprintf('offset, Wang applied (old) : left %.5f right %.5f ratio %.3f\n', r(1), r(2), r(1) / r(2));
%% 3. 0.1 mm offset, FDK default: Wang skipped on the short scan (with a warning)
vol_gated = FDK(proj, geo_off, angles);
r = lr(vol_gated);
fprintf('offset, FDK default (new) : left %.5f right %.5f ratio %.3f\n', r(1), r(2), r(1) / r(2));
%% Show the central axial slice of each
figure('Name', '200-degree scan: Wang detector-offset weights need a full circle');
subplot(1, 3, 1); imshow(squeeze(vol_ref(:, :, 32)), [0 1.5 * mu]); title('centred (reference)');
subplot(1, 3, 2); imshow(squeeze(vol_wang(:, :, 32)), [0 1.5 * mu]); title('offset, Wang applied (before)');
subplot(1, 3, 3); imshow(squeeze(vol_gated(:, :, 32)), [0 1.5 * mu]); title('offset, Wang skipped (after)');

centred detector (reference): left 0.02000 right 0.02000 ratio 1.000
0.1 mm offset, Wang weights applied (before): left 0.02156 right 0.01840 ratio 1.171
0.1 mm offset, Wang skipped on the short scan (after): left 0.02000 right 0.02000 ratio 1.000
import numpy as np
import tigre
import tigre.algorithms as algs
import matplotlib.pyplot as plt
geo = tigre.geometry_default(high_resolution=False)
geo.nVoxel = np.array([64, 64, 64])
geo.sVoxel = np.array([64.0, 64.0, 64.0])
geo.dVoxel = geo.sVoxel / geo.nVoxel
zz, yy, xx = np.mgrid[:64, :64, :64]
mu = 0.02
phantom = (((yy - 31.5) ** 2 + (xx - 31.5) ** 2 <= 20 ** 2) * mu).astype(np.float32)
core = (yy - 31.5) ** 2 + (xx - 31.5) ** 2 <= 14 ** 2
angles = np.linspace(0, np.deg2rad(200), 200) # short scan
proj = tigre.Ax(phantom, geo, angles)
def lr(vol):
left = float(vol[16:48, :, :32][core[16:48, :, :32]].mean())
right = float(vol[16:48, :, 32:][core[16:48, :, 32:]].mean())
return left, right
vol_ref = algs.fdk(proj, geo, angles) # centred detector
geo_off = tigre.geometry_default(high_resolution=False)
geo_off.nVoxel, geo_off.sVoxel, geo_off.dVoxel = geo.nVoxel, geo.sVoxel, geo.dVoxel
geo_off.offDetector = np.array([0.0, 0.1]) # 0.1 mm: a fraction of a pixel
# The old behaviour: Wang weights applied because offDetector != 0. Reproduce
# it by calling the Wang path directly on a full-circle-shaped call.
from tigre.algorithms import single_pass_algorithms as spa
_orig = spa.is_short_scan
spa.is_short_scan = lambda a: False # force the pre-fix path
vol_wang = algs.fdk(proj, geo_off, angles)
spa.is_short_scan = _orig
vol_gated = algs.fdk(proj, geo_off, angles) # new default: skipped
fig, axes = plt.subplots(1, 3, figsize=(13, 4.4))
for ax, vol, title in zip(
axes, (vol_ref, vol_wang, vol_gated),
("centred detector (reference)",
"0.1 mm offset, Wang weights applied (before)",
"0.1 mm offset, Wang skipped on the short scan (after)")):
l, r = lr(vol)
ax.imshow(vol[32], cmap="gray", vmin=0, vmax=1.5 * mu)
ax.set_title(f"{title}\nleft/right interior ratio {l / r:.2f}", fontsize=9)
ax.axis("off")
print(f"{title}: left {l:.5f} right {r:.5f} ratio {l / r:.3f}")
fig.suptitle("200-degree scan of a uniform cylinder - Wang detector-offset weights need a full circle",
fontsize=10)
plt.tight_layout()
plt.savefig("d26_short_scan_wang.png", dpi=120)
plt.show()
Total running time of the script: (0 minutes 0.497 seconds)