Package: oflibnumpy
Oflibnumpy:a handy pythonopticalflowlibrary, based onNumPyarrays, that enables
the manipulation and combination of flow fields while keeping track of valid areas (see “Usage”). It is mostly code
written from scratch, but also contains useful wrappers for specific functions from libraries such as OpenCV’sremap, to integrate them with the custom flow field class introduced by oflibnumpy. Features:Provides a custom flow field class for both backwards and forwards (‘source’ / ‘target’ based) flow fieldsProvides a number of class methods to create flow fields from lists of affine transforms, or a transformation matrixProvides a number of functions to resize the flow field, visualise it, warp images, find necessary image paddingAllows for three different types of flow field combination operationsKeeps track of valid flow field areas through said operationsProvides alternative functions to avoid the explicit use of the custom flow class, with slightly limited functionalityNote there is an equivalent flow library called Oflibpytorch, mostly based on PyTorch tensors. Itscode is available on Github, and thedocumentation is accessible on ReadTheDocs.Usage & DocumentationA user’s guide as well as full documentation of the library is available atReadTheDocs. Some quick examples:importoflibnumpyasofshape=(300,400)transform=[['rotation',200,150,-30]]# Make a flow field and display itflow=of.Flow.from_transforms(transform,shape)flow.show()# Alternative option without using the custom flow classflow=of.from_transforms(transform,shape,'t')of.show_flow(flow)Above:Visualisation of optical flow representing a rotation# Combine sequentially with another flow field, display the resultflow_2=of.Flow.from_transforms([['translation',40,0]],shape)result=flow.combine_with(flow_2,mode=3)result.show(show_mask=True,show_mask_borders=True)# Alternative option without using the custom flow classflow_2=of.from_transforms([['translation',40,0]],shape,'t')result=of.combine_flows(flow,flow_2,mode=3,ref='t')of.show_flow(result)# Note: no way to show the valid flow area (see documentation)Above:Visualisation of optical flow representing a rotation, translated to the right, using the custom flow classresult.show_arrows(show_mask=True,show_mask_borders=True)# Alternative option without using the custom flow classof.show_flow_arrows(result,'t')# Note: again no way to show the valid flow areaAbove:Visualisation of optical flow representing a rotation, translated to the right, using the custom flow classInstallationOflibnumpy is based on Python>=3.7. Install it by running:pip install oflibnumpyTestingOflibnumpy contains a large number of tests to verify it is working as intended. Use the command line to navigate
tooflibnumpy/testsand run the following code:python -m unittest discover .The tests will take several minutes to run. Successful completion will be marked withOK.Contribution & SupportSource Code:https://github.com/RViMLab/oflibnumpyIssue Tracker:https://github.com/RViMLab/oflibnumpy/issuesLicenseCopyright (c) 2021 Claudio S. Ravasio, PhD student at University College London (UCL), research assistant at King’s
College London (KCL), supervised by:Dr Christos Bergeles, PI of the Robotics and Vision in Medicine (RViM) lab in the School of Biomedical Engineering &
Imaging Sciences (BMEIS) at King’s College London (KCL)Prof Lyndon Da Cruz, consultant ophthalmic surgeon, Moorfields Eye Hospital, London UKThis code is licensed under theMIT License.If you use this code, please acknowledge us with the following citation:@article{ravasio_oflib,
  title     = {oflibnumpy {\&} oflibpytorch: Optical Flow Handling and Manipulation in Python},
  author    = {Ravasio, Claudio S. and Da Cruz, Lyndon and Bergeles, Christos},
  journal   = {Journal of Open Research Software (JORS)},
  year      = {2021},
  volume    = {9},
  publisher = {Ubiquity Press, Ltd.},
  doi       = {10.5334/jors.380}
}