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

SSIM

This method calculate SSIM each window and make SSIM map. The output value is just index, don’t have quantitative. Then it can’t be used for quantitative visualization.

<aside> 💡

BOSlib.shift.SSIM(ref_array : np.ndarray, exp_array : np.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
    -------
    np.ndarray
        The inverted SSIM difference matrix, where higher values indicate greater dissimilarity between the two images.
    """

</aside>

References:

[1] Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural simi-larity. IEEE Transactions on Image Processing, 13, 600-612.https://ece.uwaterloo.ca/~z70wang/publications/ssim. pdf , DOI:10.1109/TIP.2003.819861

Examples:

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

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

from BOSlib.shift import SSIM
shift_ssim=SSIM(ref_image,exp_image)

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_ssim, cmap="gray")
plt.title("SSIM")
plt.axis("off")

plt.show()

Output:

image.png

SP-BOS

This method is based on SP-BOS by Ota et al that seeks the centre line of stripe and make displacement map.

<aside> 💡

BOSlib.shift.SP_BOS(ref_array : np.ndarray, exp_array : np.ndarray, binarization : str ="HPfilter", thresh : int = 128, freq : int = 500)

"""
    Calculate the displacement map of stripe patterns in experimental images using the Background Oriented Schlieren (BOS) method.
    
    This function computes the relative displacement between stripes in a reference and experimental image by compensating for background movement and noise. The displacement map is calculated by processing the images through several steps including image resizing, binarization, boundary detection, noise reduction, displacement calculation, and background compensation.

    Parameters
    ----------
    ref_array : np.ndarray
        The reference grayscale image array. This image represents the original, undisturbed pattern.
        
    exp_array : np.ndarray
        The experimental grayscale image array. This image represents the pattern after deformation due to external factors.
        
    binarization : str, optional, default="HPfilter"
        The method used for binarization of the images. Options are:
        - "thresh" : Use thresholding for binarization.
        - "HPfilter" : Use high-pass filtering for binarization.
        
    thresh : int, optional, default=128
        The threshold value used for binarization when `binarization="thresh"`. Pixels with values above the threshold are set to 1, and those below are set to 0.
        
    freq : int, optional, default=500
        The frequency parameter used for high-pass filtering when `binarization="HPfilter"`.

    Returns
    -------
    np.ndarray
        A 2D array representing the displacement map of the stripe patterns, with background movement compensated. Each value represents the relative displacement between the reference and experimental images, with noise and background displacements removed.

    Notes
    -----
    The method performs the following steps:
    1. Vertically stretches both the reference and experimental images by a factor of 10.
    2. Binarizes the images using either thresholding or high-pass filtering.
    3. Identifies the upper and lower boundaries of the stripes and calculates their centers for both images.
    4. Filters out noise by removing displacements larger than a certain threshold.
    5. Computes the displacement between the stripe centers.
    6. Compensates for background movement by normalizing the displacement map, subtracting the mean displacement over a specified region.
    """

</aside>

References:

[1] Ota, M., Hamada, K., Noda, R., Kato, H., & Maeno, K. (2011). Three-Dimensional CT Measurement of Supersonic Flow Field around an Asymmetric Body by Background Oriented Schlieren (BOS) Technique. Journal of The Japan Society for Aeronautical and Space Sciences, 59, 154-159. https://doi.org/10.2322/ JJSASS.59.154.

Examples:

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

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

from BOSlib.shift import SP_BOS
shift_sp=SP_BOS(ref_image,exp_image)

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("SP-BOS")
plt.axis("off")

plt.show()

Output:

image.png