openBOS package¶
Submodules¶
openBOS.culculate_refractiveindex module¶
- openBOS.culculate_refractiveindex.SOR_2D(array_laplacian: ndarray, omega_SOR: float, e: float, tolerance: float = 1e-24, max_stable_iters: int = 1000000)¶
Performs the Successive Over-Relaxation (SOR) method on a 2D Laplacian array to solve for steady-state solutions within each slice of the array.
- Parameters:
array_laplacian (np.ndarray) – A 3D numpy array where each slice represents a 2D Laplacian grid to be solved.
omega_SOR (float) – The relaxation factor for the SOR method. Values between 1 and 2 can speed up convergence.
e (float) – The convergence tolerance threshold for each slice. Iterations stop once the change (delta) falls below this threshold.
tolerance (float, optional) – The tolerance level to determine stability in convergence. Defaults to 1e-24.
max_stable_iters (int, optional) – The maximum number of stable iterations allowed per slice before termination, regardless of convergence. Defaults to 1000000.
- Returns:
A 3D numpy array containing the steady-state solution u for each 2D slice in array_laplacian.
- Return type:
np.ndarray
Notes
The SOR method updates each element in the u array by considering its neighbors and applying the relaxation factor omega_SOR.
Boundaries are fixed to zero for each slice, enforcing Dirichlet boundary conditions.
Convergence for each slice stops either when delta is less than e or after a stable count of iterations (determined by tolerance and max_stable_iters) has been reached.
Examples
>>> laplacian = np.random.rand(10, 100, 100) # 10 slices of 100x100 grids >>> solution = SOR_2D(laplacian, omega_SOR=1.5, e=1e-6) >>> print(solution.shape) (10, 100, 100)
openBOS.reconstruction module¶
- openBOS.reconstruction.ART(sinogram, mu, e, bpos=True)¶
Perform Algebraic Reconstruction Technique (ART) to reconstruct images from a sinogram.
The ART method iteratively updates pixel values to minimize the error between projections and the input sinogram, facilitating accurate image reconstruction from projections.
- Parameters:
sinogram (np.ndarray) – A 2D or 3D numpy array representing the sinogram. Each row corresponds to a projection at a specific angle.
mu (float) – The relaxation parameter controlling the update step size during the iterative process.
e (float) – The convergence threshold for the maximum absolute error in the reconstruction.
bpos (bool, optional) – If True, enforces non-negative pixel values in the reconstruction, by default True.
- Returns:
A list of reconstructed 2D arrays, each corresponding to a projection set in the input sinogram.
- Return type:
list of np.ndarray
Notes
The function dynamically adjusts the grid size N until it matches the shape of the sinogram projections.
The radon and iradon functions from skimage.transform are used to perform forward and backward projections, respectively.
The method stops when the maximum absolute error between successive updates falls below e.
Examples
>>> sinogram = np.random.rand(180, 128) # Example sinogram with 180 projections of length 128 >>> reconstructed_images = ART(sinogram, mu=0.1, e=1e-6) >>> print(len(reconstructed_images)) 180
- openBOS.reconstruction.abel_transform(angle: ndarray, center: float, ref_x: float, G: float)¶
Perform the Abel transform to convert refractive angle values into density differences.
This function applies the Abel transform on a 2D array of refractive angles. It compensates for background movement by subtracting the mean value at a reference x-coordinate, calculates distances from the center axis, and integrates to derive density differences using the Gladstone-Dale constant.
- Parameters:
angle (np.ndarray) – A 2D numpy array representing refractive angles for each pixel.
center (float) – The index along the y-axis corresponding to the central axis of the transform.
ref_x (float) – A reference x-coordinate to compute and offset background movement.
G (float) – The Gladstone-Dale constant, used to convert the computed refractive index differences to density differences.
- Returns:
A 1D array of density differences derived from the Abel transform.
- Return type:
np.ndarray
Notes
This function calculates density differences through an integral-based approach. The refractive angle image is rotated to align with the axis of symmetry, and values are integrated from the center outwards, adjusting for axial symmetry.
Examples
>>> angle_image = np.random.rand(200, 300) # Simulated refractive angle image >>> density_differences = abel_transform(angle_image, center=150, ref_x=50, G=0.0001) >>> print(density_differences.shape) (150,)
openBOS.reconstruction_utils module¶
- openBOS.reconstruction_utils.sinogram_maker_axialsymmetry(angle)¶
Generates a sinogram with axial symmetry from a single 2D refractive angle image.
- Parameters:
angle (np.ndarray) – A 2D numpy array representing the refractive angle image. Each row in this array is broadcast across the height dimension to simulate an axially symmetric sinogram.
- Returns:
A 3D numpy array representing the sinogram with axial symmetry. Each slice along the first dimension corresponds to a projection at a different angle, where each projection is a symmetric repetition of the refractive angle row values across the height and width dimensions.
- Return type:
np.ndarray
Notes
This function assumes axial symmetry for the generated sinogram by replicating each row of the input angle image across both dimensions (height and width) for each slice in the 3D sinogram. The input image is first rotated by 90 degrees for alignment.
Examples
>>> angle_image = np.random.rand(100, 200) # A 100x200 refractive angle image >>> sinogram = sinogram_maker_axialsymmetry(angle_image) >>> print(sinogram.shape) (200, 200, 200)
openBOS.shift module¶
- openBOS.shift.SP_BOS(ref_array: ndarray, exp_array: ndarray)¶
Calculate the displacement map of stripe patterns in experimental images using the Background Oriented Schlieren (BOS) method.
- Parameters:
ref_array (np.ndarray) – The reference grayscale image array.
exp_array (np.ndarray) – The experimental grayscale image array.
- Returns:
The displacement map with background movement compensated. Each value represents the relative movement of stripes between the reference and experimental images, with noise and background displacements removed.
- Return type:
np.ndarray
Notes
The method follows these steps: 1. Vertically stretches both reference and experimental images by a factor of 10. 2. Binarizes the stretched images to detect stripe boundaries. 3. Identifies upper and lower stripe boundaries and calculates stripe centers for both images. 4. Filters noise by removing large displacement values. 5. Computes displacement between stripe centers. 6. Compensates for background movement by normalizing the displacement map.
- openBOS.shift.SSIM(ref_array: ndarray, exp_array: ndarray)¶
Compute the inverted Structural Similarity Index (SSIM) difference matrix between two grayscale images.
- Parameters:
ref_array (np.ndarray) – The reference grayscale image array.
exp_array (np.ndarray) – The experimental grayscale image array.
- Returns:
The inverted SSIM difference matrix, where higher values indicate greater dissimilarity between the two images.
- Return type:
np.ndarray
openBOS.shift_utils module¶
openBOS.utils module¶
- openBOS.utils.compute_laplacian_in_chunks_2D(array: Tensor, chunk_size: int = 100) Tensor ¶
Computes the Laplacian of an input 2D tensor in smaller chunks, allowing for memory-efficient processing of large tensors.
- Parameters:
array (torch.Tensor) – The input 2D tensor for which the Laplacian is to be computed.
chunk_size (int, optional) – The size of the chunks to be processed (default is 100).
- Returns:
The computed Laplacian of the input tensor.
- Return type:
torch.Tensor
- openBOS.utils.compute_laplacian_in_chunks_3D(array: Tensor, chunk_size: int = 100) Tensor ¶
Computes the Laplacian of an input 3D tensor in smaller chunks, allowing for memory-efficient processing of large tensors.
- Parameters:
array (torch.Tensor) – The input 3D tensor for which the Laplacian is to be computed.
chunk_size (int, optional) – The size of the chunks to be processed (default is 100).
- Returns:
The computed Laplacian of the input tensor.
- Return type:
torch.Tensor
- openBOS.utils.get_gladstone_dale_constant(temperature, pressure, humidity)¶
Calculate the Gladstone-Dale constant based on temperature, pressure, and humidity without using metpy.
- Parameters:
temperature (float) – Temperature in degrees Celsius (°C).
pressure (float) – Pressure in hectopascals (hPa).
humidity (float) – Humidity as a percentage (%).
- Returns:
- Gfloat
The calculated Gladstone-Dale constant.
- densityfloat
The density of the atmosphere.
- Return type:
tuple
- openBOS.utils.shift2angle(shift: ndarray, ref_array: ndarray, sensor_pitch: float, resolution_of_pattern: float, Lb: float, Lci: float)¶
Convert the background image displacement to the angle of light refraction.
- Parameters:
shift (np.ndarray) – Displacement values from the background image.
ref_array (np.ndarray) – Reference image array used for calculations.
sensor_pitch (float) – The pitch of the image sensor in meters.
resolution_of_pattern (float) – The resolution of the pattern in meters per pixel.
Lb (float) – Distance from the background to the object being captured(mm).
Lci (float) – Distance from the image sensor to the object being captured(mm).
- Returns:
- anglenp.ndarray
The calculated angles of light refraction.
- Lcfloat
The distance from the object to the lens.
- Lifloat
The distance from the lens to the image sensor.
- projection_ratiofloat
The ratio of projection based on the dimensions.
- Return type:
tuple