use ndarray::{Array2, Array3};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Layout {
Projection,
Sinogram,
}
#[derive(Clone, Debug)]
pub struct Tomo<T = f32> {
pub array: Array3<T>,
pub layout: Layout,
}
impl<T: Clone> Tomo<T> {
pub fn new(array: Array3<T>, layout: Layout) -> Self {
Self { array, layout }
}
pub fn n_angles(&self) -> usize {
match self.layout {
Layout::Projection => self.array.shape()[0],
Layout::Sinogram => self.array.shape()[1],
}
}
pub fn n_rows(&self) -> usize {
match self.layout {
Layout::Projection => self.array.shape()[1],
Layout::Sinogram => self.array.shape()[0],
}
}
pub fn n_cols(&self) -> usize {
self.array.shape()[2]
}
pub fn to_layout(&self, target: Layout) -> Tomo<T> {
if self.layout == target {
return self.clone();
}
let array = self.array.view().permuted_axes([1, 0, 2]).to_owned();
Tomo {
array,
layout: target,
}
}
}
#[derive(Clone, Debug)]
pub struct Volume<T = f32> {
pub array: Array3<T>,
}
impl<T> Volume<T> {
pub fn new(array: Array3<T>) -> Self {
Self { array }
}
pub fn dims(&self) -> (usize, usize, usize) {
let s = self.array.shape();
(s[0], s[1], s[2])
}
}
pub type Slice2D<T = f32> = Array2<T>;
#[derive(Clone, Debug)]
pub struct Frames<T = f32> {
pub array: Array3<T>,
}
impl<T> Frames<T> {
pub fn new(array: Array3<T>) -> Self {
Self { array }
}
pub fn count(&self) -> usize {
self.array.shape()[0]
}
}
#[derive(Clone, Debug)]
pub struct Dataset<T = f32> {
pub data: Tomo<T>,
pub flat: Option<Frames<T>>,
pub dark: Option<Frames<T>>,
pub theta: Vec<f32>,
}