Notebook
def multipass_img_deform( frame_a, frame_b, window_size, overlap, iterations, current_iteration, x_old, y_old, u_old, v_old, correlation_method="circular", subpixel_method="gaussian", do_sig2noise=False, sig2noise_method="peak2peak", sig2noise_mask=2, MinMaxU=(-100, 50), MinMaxV=(-50, 50), std_threshold=5, median_threshold=2, median_size=1, filter_method="localmean", max_filter_iteration=10, filter_kernel_size=2, interpolation_order=3, ): """ Multi pass of the PIV evaluation. This function does the PIV evaluation of the second and other passes. It returns the coordinates of the interrogation window centres, the displacement u, v for each interrogation window as well as the mask which indicates wether the displacement vector was interpolated or not. Parameters ---------- frame_a : 2d np.ndarray the first image frame_b : 2d np.ndarray the second image window_size : tuple of ints the size of the interrogation window overlap : tuple of ints the overlap of the interrogation window, e.g. window_size/2 x_old : 2d np.ndarray the x coordinates of the vector field of the previous pass y_old : 2d np.ndarray the y coordinates of the vector field of the previous pass u_old : 2d np.ndarray the u displacement of the vector field of the previous pass v_old : 2d np.ndarray the v displacement of the vector field of the previous pass subpixel_method: string the method used for the subpixel interpolation. one of the following methods to estimate subpixel location of the peak: 'centroid' [replaces default if correlation map is negative], 'gaussian' [default if correlation map is positive], 'parabolic' MinMaxU : two elements tuple sets the limits of the u displacment component Used for validation. MinMaxV : two elements tuple sets the limits of the v displacment component Used for validation. std_threshold : float sets the threshold for the std validation median_threshold : float sets the threshold for the median validation filter_method : string the method used to replace the non-valid vectors Methods: 'localmean', 'disk', 'distance', max_filter_iteration : int maximum of filter iterations to replace nans filter_kernel_size : int size of the kernel used for the filtering interpolation_order : int the order of the spline interpolation used for the image deformation Returns ------- x : 2d np.array array containg the x coordinates of the interrogation window centres y : 2d np.array array containg the y coordinates of the interrogation window centres u : 2d np.array array containing the u displacement for every interrogation window u : 2d np.array array containing the u displacement for every interrogation window mask : 2d np.array array containg the mask values (bool) which contains information if the vector was filtered """ x, y = get_coordinates(np.shape(frame_a), window_size, overlap) "calculate the y and y coordinates of the interrogation window centres" """The interpolation function dont like meshgrids as input. Hence, the edges must be extracted to provide the sufficient input. x_old and y_old are the coordinates of the old grid. x_int and y_int are the coordinates of the new grid""" import pdb # pdb.set_trace() print(f"Iteration {current_iteration}") y_old = y_old[:, 0] # y_old = y_old[::-1] x_old = x_old[0, :] print(x_old,y_old) y_int = y[:, 0] # y_int = y_int[::-1] x_int = x[0, :] print(x_int,y_int) # interpolating the displacements from the old grid onto the new grid # y befor x because of numpy works row major ip = RectBivariateSpline(y_old, x_old, u_old, kx=2, ky=2) u_pre = ip(y_int, x_int) ip2 = RectBivariateSpline(y_old, x_old, v_old, kx=2, ky=2) v_pre = ip2(y_int, x_int) # this one is doing the image deformation (see above) frame_b_deform = frame_interpolation( frame_b, x, y, u_pre, v_pre, interpolation_order=interpolation_order ) if do_sig2noise is True and \ current_iteration == iterations and \ iterations != 1: sig2noise_method = sig2noise_method else: sig2noise_method = None u, v, s2n = extended_search_area_piv( frame_a, frame_b_deform, window_size=window_size, overlap=overlap, search_area_size=window_size, width=sig2noise_mask, subpixel_method=subpixel_method, sig2noise_method=sig2noise_method ) shapes = np.array(get_field_shape(frame_a.shape, window_size, overlap)) u = u.reshape(shapes) v = v.reshape(shapes) s2n = s2n.reshape(shapes) # adding the recent displacment on to the displacment of the previous pass u += u_pre v -= v_pre # validation using gloabl limits and local median u, v, mask_g = validation.global_val(u, v, MinMaxU, MinMaxV) u, v, mask_s = validation.global_std(u, v, std_threshold=std_threshold) u, v, mask_m = validation.local_median_val( u, v, u_threshold=median_threshold, v_threshold=median_threshold, size=median_size, ) # adding masks to add the effect of alle the validations mask = mask_g + mask_m + mask_s # mask=np.zeros_like(u) # filter to replace the values that where marked by the validation if current_iteration != iterations: # filter to replace the values that where marked by the validation u, v = filters.replace_outliers( u, v, method=filter_method, max_iter=max_filter_iteration, kernel_size=filter_kernel_size, ) return x, y, u, v, s2n, mask