Image and detector offsets#

Shift the image and the detector, per scan or per angle.

Source: Python/demos/d14_Offsets.py · MATLAB/Demos/d14_Offsets.m

MATLAB version of this demo
%% DEMO 14:  Playing with offsets
%
%
% In this demo we show how to change offsets to either the image or the
% detector, and the flexibility of it.
% 
% 
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
% 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/
% Coded by:           Ander Biguri 
%--------------------------------------------------------------------------
%% Initialize
clear;
close all;

%% Define Geometry
geo=defaultGeometry('nVoxel',[128;128;128]);                     

% Offsets
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lets try simnple offset: The detector gets completelly displaced
geo.offOrigin =[0;0;0];                     % Offset of image from origin   (mm)              
geo.offDetector=[200; 200];                     % Offset of Detector            (mm)
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Auxiliary 
geo.accuracy=0.5;                           % Accuracy of FWD proj          (vx/sample)

%% Load data and generate projections 
% see previous demo for explanation
angles=linspace(0,2*pi,100);
head=headPhantom(geo.nVoxel);
projections=Ax(head,geo,angles,'interpolated');


%% lets see it
plotProj(projections,angles);

%% we will skip reconstruction of this tests because the image is outside the detector


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Second test: lets test variying offsets:

geo.offDetector=[10*sin(angles); 20*cos(angles)];                     % Offset of Detector            (mm)
projections2=Ax(head,geo,angles,'interpolated');
%% lets see it
plotProj(projections2,angles);
%% reconstruction
res=SART(projections2,geo,angles,10);
plotImg(res,'Dim',3);

%% Third test: lets vary everything

% Lets make the image smaller
geo.nVoxel=[128;128;128];                   % number of voxels              (vx)
geo.sVoxel=[256;256;256]/2;                   % total size of the image       (mm)
geo.dVoxel=geo.sVoxel./geo.nVoxel;          % size of each voxel            (mm)

geo.offDetector=[10*sin(angles); 10*cos(angles)];                     % Offset of Detector            (mm)
geo.offOrigin =[40*sin(angles);linspace(-30,30,100);40*cos(angles)];                     % Offset of image from origin   (mm)              

projections3=Ax(head,geo,angles,'interpolated');
%% lets see it
plotProj(projections3,angles);
%% reconstruction
res=SART(projections3,geo,angles,10,'OrderStrategy','ordered');
plotImg(res,'Dim',3);

Initialize#

import tigre
import numpy as np
from tigre.utilities import sample_loader
import tigre.algorithms as algs

Geometry#

geo = tigre.geometry_default(high_resolution=False)

# Offsets
## ####################################################################################
# Lets try simnple offset: The detector gets completelly displaced
geo.offOrigin = np.array([0, 0, 0])  # Offset of image from origin   (mm)
geo.offDetector = np.array([200, 200])  # Offset of Detector            (mm)
## ####################################################################################
# Auxiliary
geo.accuracy = 0.5
# Accuracy of FWD proj          (vx/sample)

## Load data and generate projections
# see previous demo for explanation
angles = np.linspace(0, 2 * np.pi, 100, endpoint=False)

# Load thorax phantom data
head = sample_loader.load_head_phantom(geo.nVoxel)
projections = tigre.Ax(head, geo, angles)

lets see it#

tigre.plotproj(projections, angles)

## we will skip reconstruction of this tests because the image is outside the detector

## #####################################################################
d14 Offsets

Second test: lets test variying offsets#

geo.offDetector = np.vstack(
    [10 * np.sin(angles), 20 * np.cos(angles)]
).T  # Offset of Detector            (mm)
projections2 = tigre.Ax(head, geo, angles)
## lets see it
tigre.plotproj(projections2, angles)
## reconstruction
res = algs.sart(projections2, geo, angles, 10)
tigre.plotimg(res, dim="z")
  • d14 Offsets
  • d14 Offsets
SART algorithm in progress.
Estimated time until completion : 00:00:05
Algorithm will finish at        : 16:51:40

Third test: lets vary everything#

# Lets make the image smaller
geo.nVoxel = np.array([128, 128, 128])  # number of voxels              (vx)
geo.sVoxel = np.array([256, 256, 256]) / 2  # total size of the image       (mm)
geo.dVoxel = geo.sVoxel / geo.nVoxel  # size of each voxel            (mm)
head = sample_loader.load_head_phantom(geo.nVoxel)

geo.offDetector = np.vstack(
    [10 * np.sin(angles), 10 * np.cos(angles)]
).T  # Offset of Detector            (mm)
geo.offOrigin = np.vstack(
    [40 * np.sin(angles), np.linspace(-30, 30, len(angles)), 40 * np.cos(angles)]
).T  # Offset of image from origin   (mm)

projections3 = tigre.Ax(head, geo, angles)
## lets see it
tigre.plotproj(projections3, angles)
## reconstruction
res = algs.sart(projections3, geo, angles, 10)
tigre.plotimg(res, dim="z")
  • d14 Offsets
  • d14 Offsets
SART algorithm in progress.
Estimated time until completion : 00:00:10
Algorithm will finish at        : 16:52:06

Total running time of the script: (1 minutes 6.342 seconds)

Gallery generated by Sphinx-Gallery