Giter Site home page Giter Site logo

sailfish009 / godec Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrewssobral/godec

0.0 1.0 0.0 1.55 MB

Python implementation of the GoDec algorithm from Zhou and Tao (ICML 2011) for low-rank and sparse representation

License: MIT License

Python 98.19% Shell 1.81%

godec's Introduction

GoDec

Python implementation of the GoDec algorithm from Zhou and Tao (ICML 2011) for low-rank and sparse representation. GoDec is one of the most efficient algorithm for low-rank and sparse decomposition thanks to bilateral random projections (BRP), a fast approximation of SVD/PCA.

Requirements

  • numpy
  • scipy
  • sklearn
  • arparse, time (for demos)
  • matplotlib (optional, to visualize the results)
  • opencv (optional, to read video files)

Demo using OpenCV

Simple demo using data from video file with OpenCV:

# Import libraries
import cv2 as cv
import time
from numpy import array, column_stack
from godec import godec
from utils import play_2d_results

# Open video file
cap = cv.VideoCapture('dataset/demo.avi')

# Read until video is completed
M = None
height = None
width = None
i = 0
print("Press 'q' to stop...")
while cap.isOpened():
    # Capture frame-by-frame
    ret, frame = cap.read()
    if ret:
        frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        height, width = frame.shape

        # Stack frame as a column vector
        F = frame.T.reshape(-1)

        if i == 0:
            M = array([F]).T
        else:
            M = column_stack((M, F))

        # Display the resulting frame
        cv.imshow('Frame', frame)

        # Press Q on keyboard to exit
        if cv.waitKey(25) & 0xFF == ord('q'):
            break

        i = i + 1

    # Break the loop
    else:
        break

# Release the video capture object
cap.release()

# Closes all the windows
cv.destroyAllWindows()

# Decompose
print("Number of frames: ", i, " with size ", (width, height))
print("Processing M with shape ", M.shape)
t = time.time()
L, S, LS, _ = godec(M)
elapsed = time.time() - t
print(elapsed, "sec elapsed")

# Play results
play_2d_results(M, LS, L, S, width, height)

For more info, see godec_opencv.py

Demo using MATLAB data

Simple demo using data from MATLAB:

# Import libraries
import time
import scipy.io as sio

from godec import godec
from utils import play_2d_video, play_2d_results

# Load data
mat = sio.loadmat('dataset/demo.mat')
M, height, width = mat['M'], int(mat['m']), int(mat['n'])

# Play input data
play_2d_video(M, width, height)

# Decompose
t = time.time()
L, S, LS, _ = godec(M)
elapsed = time.time() - t
print(elapsed, "sec elapsed")

# Play results
play_2d_results(M, LS, L, S, width, height)

For more info, see godec_matlab.py

More examples

python godec_demo.py dataset/highway.mpg True
python godec_demo.py dataset/demo.avi True
python godec_demo.py dataset/demo.mat True

License

MIT

godec's People

Contributors

andrewssobral avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.