STIR  6.3.0
fftshift.h
Go to the documentation of this file.
1 #ifndef __stir_numerics_fftshift_H__
2 #define __stir_numerics_fftshift_H__
3 /*
4  Copyright (C) 2025, University College London
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
26 #include "stir/Array.h"
27 #include <complex>
28 #include <utility> // for std::swap
29 
30 START_NAMESPACE_STIR
31 
33 template <typename T>
34 inline void
35 fftshift(Array<1, T>& a, int size)
36 {
37  for (int i = 0; i < size / 2; ++i)
38  std::swap(a[i], a[size / 2 + i]);
39 }
40 
42 template <typename T>
43 inline void
44 fftshift(Array<2, std::complex<T>>& a, int size)
45 {
46  // swap left/right halves across all rows
47  for (int i = 0; i < size; ++i)
48  for (int j = 0; j < size / 2; ++j)
49  std::swap(a[i][j], a[i][size / 2 + j]);
50 
51  // swap top/bottom halves across all columns
52  for (int i = 0; i < size; ++i)
53  for (int j = 0; j < size / 2; ++j)
54  std::swap(a[j][i], a[size / 2 + j][i]);
55 }
56 
57 END_NAMESPACE_STIR
58 #endif
defines the stir::Array class for multi-dimensional (numeric) arrays
void fftshift(Array< 2, std::complex< T >> &a, int size)
In-place 2D fftshift: quadrant swap (left-right, then top-bottom). Accepts complex arrays...
Definition: fftshift.h:44