Optical flow library using a custom flow class based on NumPy arrays
Project description
Oflibnumpy: a handy python optical flow library, based on NumPy arrays, 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’s remap, 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 fields
Provides a number of class methods to create flow fields from lists of affine transforms, or a transformation matrix
Provides a number of functions to resize the flow field, visualise it, warp images, find necessary image padding
Allows for three different types of flow field combination operations
Keeps track of valid flow field areas through said operations
Provides alternative functions to avoid the explicit use of the custom flow class, with slightly limited functionality
Note there is an equivalent flow library called Oflibpytorch, mostly based on PyTorch tensors. Its code is available on Github, and the documentation is accessible on ReadTheDocs.
Usage & Documentation
A user’s guide as well as full documentation of the library is available at ReadTheDocs. Some quick examples:
import oflibnumpy as of
shape = (300, 400)
transform = [['rotation', 200, 150, -30]]
# Make a flow field and display it
flow = of.Flow.from_transforms(transform, shape)
flow.show()
# Alternative option without using the custom flow class
flow = 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 result
flow_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 class
flow_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 class
result.show_arrows(show_mask=True, show_mask_borders=True)
# Alternative option without using the custom flow class
of.show_flow_arrows(result, 't') # Note: again no way to show the valid flow area
Above: Visualisation of optical flow representing a rotation, translated to the right, using the custom flow class
Installation
Oflibnumpy is based on Python>=3.7. Install it by running:
pip install oflibnumpy
Testing
Oflibnumpy contains a large number of tests to verify it is working as intended. Use the command line to navigate to oflibnumpy/tests and run the following code:
python -m unittest discover .
The tests will take several minutes to run. Successful completion will be marked with OK.
Contribution & Support
Source Code: https://github.com/RViMLab/oflibnumpy
Issue Tracker: https://github.com/RViMLab/oflibnumpy/issues
License
Copyright (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 UK
This code is licensed under the MIT 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}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file oflibnumpy-1.1.1.tar.gz
.
File metadata
- Download URL: oflibnumpy-1.1.1.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 pkginfo/1.7.0 requests/2.23.0 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e51631cf0b1d47cb1dcb220b12881625f490c01683a5ded30e2a7666054a9ef6 |
|
MD5 | dbbedf57151ed62661d699538aceb530 |
|
BLAKE2b-256 | 31196f73fecdd9810c246d3f12bae8c85f46dfb15ab5c9d270f014786f8c5992 |
File details
Details for the file oflibnumpy-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: oflibnumpy-1.1.1-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 pkginfo/1.7.0 requests/2.23.0 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ee14bafdb9b2b10ba48312e85af2232a509f98bd06dddaa4142d87445fc6f3 |
|
MD5 | 99ca45daea7efc1ca3852fcdf573a15f |
|
BLAKE2b-256 | 77ec2e29efb8ef87911e43e324f41cf7387d739de99e85b92e47dc64c0cc5659 |