Utils module

OpFlowLab.functions.utils.imadjust(image, in_bound=(0.001, 0.999), out_bound=(0, 1))[source]

Performs contrast adjustment on an image

Parameters
imagendarray

Input image.

in_boundtuple

Tuple specifying the lower and upper percentile with which to set the input contrast limit.

out_boundtuple

Tuple specifying the lower and upper percentile with which to set the output contrast limit.

Returns
outputndarray

Contrast adjusted output image.

Notes

See https://stackoverflow.com/questions/39767612/what-is-the-equivalent-of-matlabs-imadjust-in-python/44529776#44529776

OpFlowLab.functions.utils.load_velocity_bin(bin_file, shape, bin_dtype='float32', kernel_size=5, replace_nan=True)[source]

Returns the list of files containing the velocity fields.

Parameters
bin_filestr

Path to the binary file to load.

shapetuple

Tuple containing the dimensions to reshape the binary data to.

bin_dtype{“float32”, “float16”}

Dtype that the binary array is encoded with.

kernel_sizeint

Size of the median filter used.

replace_nanbool

Specifies if NaN values should be replaced with a value of 0

Returns
velocityarray_like

Array containing the velocities loaded from bin_file

OpFlowLab.functions.utils.load_velocity_filelist(folder, velocity_type='dense', xy_folder_list=('flowx', 'flowy'), file_ext='*.bin', reverse_sort=False)[source]

Returns the list of files containing the velocity fields.

Parameters
folderstr

Input folder

velocity_type{‘dense’, ‘sparse’}

Specifies the type of velocity field.

xy_folder_listtuple

Subfolders to search for the x and y component of the velocity field. Only used when the velocity type is ‘dense’.

file_extstr

Regex string specifying the file extension.

reverse_sortbool

Specify if the files should be sorted in the reverse order instead of the forward order.

Returns
list

If the velocity type is ‘dense’, returns a list containing two file lists pointing to the x component and y component of the velocity field. If the velocity type is ‘sparse’, returns a list containing a single file list.

OpFlowLab.functions.utils.load_velocity_piv(vector_file, frame_no)[source]

Loads the velocity field from the output from PIVLab.

Parameters
vector_filestr

Path to the MATLAB file to load.

frame_notuple

Frame number of the velocity field that is to be loaded.

Returns
flow_xarray_like

Array containing the x component of the velocity field

flow_yarray_like

Array containing the y component of the velocity field

xarray_like

Array containing the x coordinates of the velocity field

yarray_like

Array containing the y coordinates of the velocity field

OpFlowLab.functions.utils.save_output(array, filename, save_velocity_as_tif=False, save_dtype='float16')[source]

Helper function used to save the velocity field.

Parameters
arrayarray_like

Array to be saved.

filenamestr

Filename used to save the array.

save_velocity_as_tifbool

Determines if the array should be saved as a tiff or a binary file.

save_dtype{“float32”, “float16”}

Specifies if the array should be saved as a float32 array or float 16 array.