This file provides the utilities.
This method converts the displacement to refraction angle.
<aside> 💡
BOSlib.utils.shift2angle(shift: np.ndarray, ref_array: np.ndarray, sensor_pitch: float, resolution_of_background: float, Lb: float, Lci: float, binarization : str ="HPfilter", thresh : int = 128, freq : int = 500)
"""
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 mm.
resolution_of_background : float
It represents the number of lines per mm.
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).
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
-------
tuple
- angle : np.ndarray
The calculated angles of light refraction.
- Lc : float
The distance from the object to the lens.
- Li : float
The distance from the lens to the image sensor.
- projection_ratio : float
The ratio of projection based on the dimensions.
"""
</aside>
Note:
Examples:
from BOSlib.utils import shift2angle
angle,Lc,Li,Projection_Ratio=shift2angle(shift = shift, ref_array = ref_image, sensor_pitch = 0.004220546, resolution_of_background = 10, Lb = 30, Lci = 532)
print(Lc,Li,Projecction_Ratio)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(shift, cmap="gray")
plt.colorbar()
plt.title("Reference Image")
plt.axis("off")
plt.subplot(1, 2, 2)
plt.imshow(angle, cmap="gray")
plt.colorbar()
plt.title("Experimental Image")
plt.axis("off")
plt.show()
Output:
0.27733443890895615 0.2546655610910439 0.8286268274883615
This method calculate Gladstone-Dale constant that is necessary to convert refractive index to density.
<aside> 💡
BOSlib.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
-------
tuple
- G : float
The calculated Gladstone-Dale constant.
- density : float
The density of the atmosphere.
"""
</aside>
Note:
We are assuming an ideal gas
Examples: