%matplotlib inline
import numpy as np

Direct Calibration#

For this tutorial we will use files contained in the fluidimage repository. We assume that fluidimage has been installed with python setup.py develop and we deduce the path of the repository from the path of the package fluidimage:

from fluidimage import get_path_image_samples

We first import the class CalibDirect

from fluidimage.calibration import CalibDirect

Give number of pixels of images and the path of grid points made by UVMAT

path_cam = (get_path_image_samples() /
            '4th_PIV-Challenge_Case_E/E_Calibration_Images/Camera_01')
glob_str_xml = path_cam / 'img*.xml'
shape_img = 1024, 1024
calib = CalibDirect(glob_str_xml, shape_img)

We now compute interpolents able to compute the physical coordinates from the indices in the images and (for each level)

calib.compute_interpolents()

The quality of this step can be checked with the function check_interp_levels

calib.check_interp_levels()
../_images/3a6d52fdcb89a634a5739422b220b1713c442445170b048c44dd1b23ce78603d.png ../_images/452dccc465610d35d97647aa7658c4812f162efd7fec26ca446ab9d169e05567.png ../_images/ed86a38ff99c90af6654c063d459493456ffca65081ef0cc985db009dcde6694.png ../_images/c9609d158d08b9a501ddcb962cc40a753d73e4beb0c030db04b15962b3f12110.png ../_images/619706cb8de5458552d4fbc40abecb4c4a094e573767d57f0fd3be173f096f74.png ../_images/077254a92d1469f0554e3a2b8901164d9dcdff00cd30128095fd9bf64b4e8caf.png ../_images/6a4e0668db9d68e37ee5e738733c5d5fd7d4602e90def8274ee17fdb5693eec9.png ../_images/467e87da103d595a327e8ecfa2f6578353c91375eb14f9e2cce965606567ced3.png ../_images/2f6a027f9910eb9d1e9ffac265136bd28e4e73fca3ced62d26bd1d5f99934b41.png ../_images/6e06f388d7a4a6da4854b87f6da1aa8c18c62c9dc6f2dac3774263a4d4dc7a47.png ../_images/c6223162c3c8e2c81c4286301293cfa050bb1a54efffc2b546a93f212fa108cc.png ../_images/72f8fcc9249d5cc9dc452ccc954dea9da2eb33b0f02368c3aab4f4400a32970e.png ../_images/818b1a44933d6c1fd900cffb60d71b74645dc4b18b37b12af9081d67352e50c5.png ../_images/d99637c7393ec227ff1e89525989ab7835c31016c7f0a4718f3d195f91988dbe.png

And finally, we compute the interpolents for equations of optical paths from nbline_x * nbline_y lines and save the calibration

nb_lines_x, nb_lines_y = 128, 64
calib.compute_interpolents_pixel2line(nb_lines_x, nb_lines_y, test=False)
calib.save(path_cam / 'calib1.npy')

It is very important to check that everything seems all right because it is easy to make something wrong with such calibration.

calib.check_interp_lines()
../_images/0f7f387cf7afc1912a50e410139b43510e1bc61900801d0b94c88659d19bc821.png
calib.check_interp_lines_coeffs()
../_images/d063781e2fee7418e4ca6f52db1ed07dbbaf2d83d4ec037dfc70a52a0f2d4436.png ../_images/5e97904d0d3a03a3c3e1cbc23171a635d117ef3e442c14d5a0da217cd25d64d2.png ../_images/c9187a2fb8367ac87a2f4624fb0f1ff343b9a46c61d5f274a557f596a5b4ad03.png ../_images/3aa25779084b63f57af3ccc2d4428bd5906801edbf463133f7f2d8084206869c.png ../_images/4c611b84ede5bd6de28d77328220e268078d943c86990ce972be567231321b6f.png ../_images/53a6834079848d8eaf30cf9a75084fc5dc75d22e883c1e31fb418123fd59cff9.png ../_images/d3441fadf4ce4fe92627acba62b51e744e449108124f04d24fe0ff371b9439e6.png
from fluidimage.calibration.util import get_plane_equation
z0 = 0.05
alpha = 0
beta = 0
a, b, c, d = get_plane_equation(z0, alpha, beta)
indx = np.arange(100, 1000, 100)
indy = np.arange(100, 1000, 100)

calib.intersect_with_plane(indx, indy, a, b, c, d)
array([[-0.00671866,  0.05637488,  0.05      ],
       [ 0.0007478 ,  0.04863884,  0.05      ],
       [ 0.00846414,  0.04101173,  0.05      ],
       [ 0.01589005,  0.03330709,  0.05      ],
       [ 0.02338467,  0.02571621,  0.05      ],
       [ 0.03096371,  0.0183319 ,  0.05      ],
       [ 0.03840155,  0.01049245,  0.05      ],
       [ 0.04587657,  0.00284014,  0.05      ],
       [ 0.05364159, -0.00467532,  0.05      ]])
dx = np.random.randint(0, 5, indx.size)
dy = np.random.randint(0, 5, indx.size)
calib.apply_calib(indx, indy, dx, dy, a, b, c, d)
array([[ 7.35324172e-05, -7.74793539e-05,  0.00000000e+00],
       [ 1.52515171e-04, -2.29949766e-04,  0.00000000e+00],
       [ 2.31420116e-04, -1.52680845e-04,  0.00000000e+00],
       [ 2.20240547e-04, -3.06420251e-04,  0.00000000e+00],
       [ 2.27645125e-04, -1.50275970e-04,  0.00000000e+00],
       [ 3.06642738e-04, -2.26859559e-04,  0.00000000e+00],
       [ 2.98526967e-04, -3.09624748e-04,  0.00000000e+00],
       [ 2.27876878e-04, -2.25056654e-04,  0.00000000e+00],
       [ 2.33621937e-04, -3.03555490e-04,  0.00000000e+00]])