This file mainly provide the methods to calculate the displacement in two images based on Background Orineted Schlieren method on GPU.

S_BOS_GPU

The method is based on Simplified-BOS by Akatsuka et al that calculate the phase difference to assume stripe as signal and make displacement map, and it was GPU paralyzed by using PyTorch and CUDA.

<aside> 💡

S_BOS_GPU(image_ref, image_exp, device, batch_size=5000):

"""
    Compute the phase shift (displacement field) between two images using 1D BOS processing.
    
    This function loads the reference and experimental images to the GPU, detects the fundamental
    frequency from a selected column of the reference image, processes the signals in batches using 
    bandpass filtering and amplitude normalization, computes the phase difference via a low-pass 
    filtered product, and finally converts the phase shift into a displacement field.
    
    Parameters:
        image_ref (numpy.ndarray): Reference image (grayscale or single channel).
        image_exp (numpy.ndarray): Experimental image (grayscale or single channel).
        device (torch.device or str): Device to perform computations (e.g., 'cuda' or 'cpu').
        batch_size (int, optional): Number of columns to process per batch. Default is 64.
        
    Returns:
        numpy.ndarray: Displacement field computed from the phase shift.
    """

</aside>

References:

[1] 赤塚 純一, 永井 伸治, 本阿弥 眞治, Background Oriented Schlieren法に基づく密度勾配の可視化法の改良, 日本機械学会論文集B編, 2011, 77 巻, 784 号, p. 2391-2400, 公開日 2011/12/25, Online ISSN 1884-8346, https://doi.org/10.1299/kikaib.77.2391

[2] Yuki Ogasawara, Narumi Nose, Shin Sakuma, Ayumu Ishibashi,and Shinsuke Udagawa. Refractive Displacement Calculation with GPU-based Acceleration for the BOS Method using Stripe Patterned Background Image. ISFV21 (Unpublished so far)

Examples:

import numpy as np
import cv2
import matplotlib.pyplot as plt
import torch
import time

ref_image=np.array(cv2.imread(r"/content/DSC_2409.JPG",cv2.IMREAD_GRAYSCALE))
exp_image=np.array(cv2.imread(r"/content/DSC_2410.JPG",cv2.IMREAD_GRAYSCALE))

from BOSlib_GPU.shift import S_BOS_GPU

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(device)
start_time = time.time()
shift_sp=S_BOS_GPU(ref_image,exp_image,device,batch_size=6000)
end_time = time.time()
ExecutionTime=end_time-start_time

plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)
plt.imshow(ref_image, cmap="gray")
plt.title("Reference Image")
plt.axis("off")

plt.subplot(1, 3, 2)
plt.imshow(exp_image, cmap="gray")
plt.title("Experimental Image")
plt.axis("off")

plt.subplot(1, 3, 3)
plt.imshow(shift_sp, cmap="gray")
plt.title(f"S-BOS_GPU in {ExecutionTime:.2f}")
plt.axis("off")

plt.show()

Output:

image.png