Home

Awesome

View LRSLibrary on File Exchange

Last Page Update: 29/07/2022, Previous Page Update: 07/03/2020

Latest Library Version: 1.0.11 (see Release Notes for more info)

LRSLibrary

Low-Rank and Sparse tools for Background Modeling and Subtraction in Videos.

The LRSLibrary provides a collection of low-rank and sparse decomposition algorithms in MATLAB. The library was designed for moving object detection in videos, but it can be also used for other computer vision and machine learning problems (for more information, please see here and here). Currently the LRSLibrary offers more than 100 algorithms based on matrix and tensor methods. The LRSLibrary was tested successfully in several MATLAB versions (e.g. R2014, R2015, R2016, R2017, on both x86 and x64 versions). It requires minimum R2014b.

<p align="center"><img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/lrs_results2.png" /></p> <p align="center"><img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/lrs-opt.gif" /></p>

See also:

Presentation about Matrix and Tensor Tools for Computer Vision
http://www.slideshare.net/andrewssobral/matrix-and-tensor-tools-for-computer-vision

MTT: Matlab Tensor Tools for Computer Vision
https://github.com/andrewssobral/mtt

IMTSL: Incremental and Multi-feature Tensor Subspace Learning
https://github.com/andrewssobral/imtsl

Citation

If you use this library for your publications, please cite it as:

@incollection{lrslibrary2015,
author    = {Sobral, Andrews and Bouwmans, Thierry and Zahzah, El-hadi},
title     = {LRSLibrary: Low-Rank and Sparse tools for Background Modeling and Subtraction in Videos},
booktitle = {Robust Low-Rank and Sparse Matrix Decomposition: Applications in Image and Video Processing},
publisher = {CRC Press, Taylor and Francis Group.}
year      = {2015}
}

Additional reference:

@article{bouwmans2015,
author    = {Bouwmans, Thierry and Sobral, Andrews and Javed, Sajid and Jung, Soon Ki and Zahzah, El-hadi},
title     = {Decomposition into Low-rank plus Additive Matrices for Background/Foreground Separation: {A} Review for a Comparative Evaluation with a Large-Scale Dataset},
journal   = {CoRR},
volume    = {abs/1511.01245}
year      = {2015},
url       = {http://arxiv.org/abs/1511.01245}
}

Stargazers over time

Stargazers over time

Install

Just do the following steps:

$ git clone --recursive https://github.com/andrewssobral/lrslibrary.git

>> lrs_setup

That's all!

GUI

The LRSLibrary provides an easy-to-use graphical user interface (GUI) for background modeling and subtraction in videos. First, run the setup script lrs_setup (or run('C:/lrslibrary/lrs_setup')), then run lrs_gui, and enjoy it!

<p align="center">(Click in the image to see the video)</p> <p align="center"> <a href="https://www.youtube.com/watch?v=zziJ7-WnvV8" target="_blank"> <img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/lrslibrary_gui2.png" width="500" border="0" /> </a> </p>

Each algorithm is classified by its cpu time consumption with the following icons:

<p align="center"><img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/time_legend.png" width="300" /></p>

The algorithms were grouped in eight categories: RPCA for Robust PCA, ST for Subspace Tracking, MC for Matrix Completion, TTD for Three-Term Decomposition, LRR for Low-Rank Representation, NMF for Non-negative Matrix Factorization, NTF for Non-negative Tensor Factorization, or TD for standard Tensor Decomposition.

List of the algorithms available in LRSLibrary

Usage example

For complete details and examples, please see the demo.m file.


%% First run the setup script
lrs_setup; % or run('C:/lrslibrary/lrs_setup')

%% Load configuration
lrs_load_conf;

%% Load video
input_avi = fullfile(lrs_conf.lrs_dir,'dataset','demo.avi');
output_avi = fullfile(lrs_conf.lrs_dir,'output','output.avi');

%% Processing videos
%
% Robust PCA
process_video('RPCA', 'FPCP', input_avi, output_avi);
% Subspace Tracking
process_video('ST', 'GRASTA', input_avi, output_avi);
% Matrix Completion
process_video('MC', 'GROUSE', input_avi, output_avi);
% Low Rank Recovery
process_video('LRR', 'FastLADMAP', input_avi, output_avi);
% Three-Term Decomposition
process_video('TTD', '3WD', input_avi, output_avi);
% Non-Negative Matrix Factorization
process_video('NMF', 'ManhNMF', input_avi, output_avi);
% Non-Negative Tensor Factorization
process_video('NTF', 'bcuNCP', input_avi, output_avi);
% Tensor Decomposition
process_video('TD', 'Tucker-ALS', input_avi, output_avi);

%% Processing matrices and tensors
%
load('dataset/trafficdb/traffic_patches.mat');
V = im2double(imgdb{100});
show_3dvideo(V);

%% Matrix-based algorithms
%
[M,m,n,p] = convert_video3d_to_2d(V);
show_2dvideo(M,m,n);

% Robust PCA
out = run_algorithm('RPCA', 'FPCP', M);
% Subspace Tracking
out = run_algorithm('ST', 'GRASTA', M);
% Matrix Completion
obs = 0.5; % Percentual of observed entries [0...1]
[params.Idx, params.Omega] = subsampling(M, obs);
out = run_algorithm('MC', 'GROUSE', M, params);
% Low Rank Recovery
out = run_algorithm('LRR', 'FastLADMAP', M);
% Three-Term Decomposition
out = run_algorithm('TTD', '3WD', M);
% Non-Negative Matrix Factorization
out = run_algorithm('NMF', 'ManhNMF', M);

% Show results
show_results(M,out.L,out.S,out.O,p,m,n);

%% Tensor-based algorithms
T = tensor(V);

% Non-Negative Tensor Factorization
out = run_algorithm('NTF', 'bcuNCP', T);
% Tensor Decomposition
out = run_algorithm('TD', 'Tucker-ALS', T);

% Show results
show_3dtensors(T,out.L,out.S,out.O);
<p align="center"><img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/lrs_results.png" width="650" /></p>

CPU time consumption

The figure below shows the average CPU time consumption and the speed classification of each algorithm to decompose a 2304x51 matrix or 48x48x51 tensor data. Both matrix and tensor data were built from dataset/demo.avi file. The experiments were performed in a Intel Core i7-3740QM CPU 2.70GHz with 16Gb of RAM running MATLAB R2013b and Windows 7 Professional SP1 64 bits.

A complete review evaluating the algorithms in many specific criterias will be published in a paper journal soon

<p align="center"><img src="https://raw.githubusercontent.com/andrewssobral/lrslibrary/master/figs/algorithms_by_speed.png" /></p>

About LRSLibrary

The LRSLibrary has been developed by Andrews Sobral thanks especially to Thierry Bouwmans for his continued support and for collaborating on this important initiative. I'm grateful to all authors who have contributed in some way to the success of the LRSLibrary.

How to contribute with LRSLibrary project

Everyone is invited to cooperate with the LRSLibrary project by sending to us any implementation of low-rank and sparse decomposition algorithms.

Option 1: email it to me (andrewssobral at gmail dot com).

Option 2: fork the library on GitHub, push your changes, then send me a pull request.

For the Option 2 you can follow the instructions below:

  1. Create the algorithm folder in lrslibrary/algorithms/XYZ/ where "XYZ" is one of the following methods: RPCA (for Robust PCA), ST (for Subspace Tracking), MC (for Matrix Completion), LRR (for Low Rank Recovery), TTD (for Three-Term Decomposition), NMF (for Non-Negative Matrix Factorization), NTF (for Non-Negative Tensor Factorization), and TD (for Tensor Decomposition).

  2. Create a run_alg.m script file to execute your algorithm, all run_alg.m files are called automatically by the lrslibrary and each of them receives a full rank matrix/tensor named "M" or "T" for a matrix-based or a tensor-based algorithm, respectively. For the matrix M, each column is a vectorized version of a gray-scale frame. The number of columns in M is the number of frames given a video, and the number of rows represents the number of pixels in the frame. For the tensor T each frontal slice represents a frame given a video.

2.1) For the matrix/tensor completion case you need to define a random sub-sampling matrix/tensor named "Idx" that indicates which elements from the input matrix/tensor (M or T) are observed (setting 1's and 0's for observed and unobserved elements, respectively).

  1. The output of your run_alg.m script file are a matrix/tensor named "L" that represents the low-rank component, and a matrix/tensor named "S" that represents the sparse components.

  2. The last step is to add your algorithm details in the lrs_algorithms.dat file (open it as text file): https://github.com/andrewssobral/lrslibrary/blob/master/lrs_algorithms.dat For example: XYZ | ABB | NAME_REFERENCE | SPEED_CLASS where:

i.e.: RPCA | FPCP | Fast PCP (Rodriguez and Wohlberg, 2013) | 1

That's all ;-)

License

The LRSLibrary is free and open source for academic/research purposes (non-commercial)¹.

¹ Some algorithms of the LRSLibrary are free for commercial purposes and others not. First you need to contact the authors of your desired algorithm and check with them the appropriate license.

Problems or Questions

If you have any problems or questions, please contact the author: Andrews Sobral (andrewssobral at gmail dot com)

Release Notes: