Optical flow library using a custom flow class based on PyTorch tensors
Project description
Oflibpytorch: a handy python optical flow library, based on PyTorch tensors, 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 PyTorch’s grid_sample, to integrate them with the custom flow field class introduced by oflibpytorch. 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
Oflibpytorch is based on oflibnumpy (code on GitHub, documentation on ReadTheDocs) and is aimed at allowing the same operations to be performed with torch tensors instead of numpy arrays as far as currently feasible, and on the GPU if required.
Usage & Documentation
A user’s guide as well as full documentation of the library is available at ReadTheDocs. Some quick examples:
import oflibpytorch as of
# Make a flow field and display it
shape = (300, 400)
flow = of.Flow.from_transforms([['rotation', 200, 150, -30]], shape)
flow.show()
# Combine sequentially with another flow field, display the result
flow_2 = of.Flow.from_transforms([['translation', 40, 0]], shape)
result = of.combine_flows(flow, flow_2, mode=3)
result.show(show_mask=True, show_mask_borders=True)
result.show_arrows(show_mask=True, show_mask_borders=True)
Installation
In order for oflibpytorch to work, the python environment needs to contain a PyTorch installation. To enable GPU usage, the CUDA Toolkit is required as well. As it is difficult to guarantee an automatic installation via pip will use the correct versions and work on all operating systems, it is left to the user to install PyTorch and Cudatoolkit independently. The easiest route is a virtual conda environment and the recommended install command from the PyTorch website, configured for the user’s specific system. To install oflibpytorch itself, use the following command:
pip install oflibpytorch
Contribution & Support
Source Code: https://github.com/RViMLab/oflibpytorch
Issue Tracker: https://github.com/RViMLab/oflibpytorch/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.
Project details
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
Hashes for oflibpytorch-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9400e477a00ab7dc5bfaf0982269e26b3eb25b0f250f8db2c9881043465c2815 |
|
MD5 | fe9d18c975c66344724da1f7f965a516 |
|
BLAKE2b-256 | ddb7ababef6aa1d4a085bea6eb0a5a91eb133e3cfbd0660cbf8e188dea0b73d7 |