Skip to main content

A package for sparse representations and dictionary learning

Project description

Sparselandtools

PyPI - Python Version PyPI PyPI - Implementation Read the DocsBuild Status

Sparselandtools is a Python 3 package that provides implementations for sparse representations and dictionary learning. In particular, it includes implementations for

For Sparse Representations:

  • Matching Pursuit
  • Orthogonal Matching Pursuit (CUDA Version availabe)
  • Thresholding Pursuit
  • Basis Pursuit

For Dictionaries in General:

  • Mutual Coherence
  • DCT Dictionary
  • Haar Dictionary
  • Overcomplete DCT Dictionary
  • Visualization Tools for Dictionaries

For Dictionary Learning:

  • K-SVD Algorithm
  • Approximate K-SVD Algorithm (CUDA Version availabe)
  • Double Sparsity Algorithm
  • Trainlets

Note: I did this project mainly to generate plots for my Master's thesis. The provided implementations are more educational than efficient. If you want to learn more about sparse representations and dictionary learning using Python, this package is for you. If you want to use the functions for industrial applications, you should have a look at more efficient C++-based implementations.

Getting Started

Sparselandtools is available as a PyPI package. You can install it using

pip install sparselandtools

Example 1: Dictionaries

DCT and Haar Dictionary

The following code creates a redundant (=overcomplete) DCT-II dictionary and plots it. It also prints out the dictionaries mutual coherence.

from sparselandtools.dictionaries import DCTDictionary
import matplotlib.pyplot as plt

# create dictionary
dct_dictionary = DCTDictionary(8, 11)

# plot dictionary
plt.imshow(dct_dictionary.to_img())
plt.show()

# print mutual coherence
print(dct_dictionary.mutual_coherence())

Example 2: Matching Pursuit

Simple Denoising using Matching Pursuit

Example 3: K-SVD Dictionary Learning

K-SVD Dictionary Learning

Example 4: K-SVD Image Denoising

from sparselandtools.applications.denoising import KSVDImageDenoiser
from sparselandtools.applications.utils import example_image
from sparselandtools.pursuits import MatchingPursuit
from sparselandtools.dictionaries import DCTDictionary

# load input image
original_img = example_image('Barbara', 512)
noisy_img = example_image('Barbara', 512, noise_std=40)

# initialize denoiser
initial_dictionary = DCTDictionary(8, 11)
denoiser = KSVDImageDenoiser(initial_dictionary, pursuit=MatchingPursuit)

# denoise image
z, d, a = denoiser.denoise(noisy_img, sigma=20, patch_size=patch_size,
                           n_iter=4, multiplier=0.5, noise_gain=1.075)

# plot denoised image
plt.imshow(z)

Documentation and Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
sparselandtools-1.0.0.dev11-py3-none-any.whl (34.4 kB) Copy SHA256 hash SHA256 Wheel py3 Nov 11, 2018
sparselandtools-1.0.0.dev11.tar.gz (16.2 kB) Copy SHA256 hash SHA256 Source None Nov 11, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page