PyKSVD
PyKSVD is a Python implementation of the K-SVD algorithm based on paper K-SVD: An Algorithm for Designing Overcomplete Dictionaries for Sparse Representation (2006) by Michal Aharon, Michael Elad, and Alfred Bruckstein.
For the evaluation (Time Series 2024) :
Notebook are present in folder notebook
notebooks/ksvd_theory.ipynbis used to understand theory behind K-SVDnotebooks/ksvd_synthetic.ipynbis used to reproduce synthetic results with noisingnotebooks/ksvd_images.ipynbis used to reproduce image denoising and pixel update (black and white only, run example inexample_corrupted_image.pyfor colored reconstructions)
Examples
- Signal Processing : Fit a dictionay based on input signals and then transform new signals with high level sparsity.
- Image processing : Denoise or complete a corrupted image with missing pixels with patches.
Installation
pip install pyksvd
Example
For signals : (example in example.py)
from pyksvd.pyksvd import KSVD
import numpy as np
# Define parameters
N = 1500 # number of training signals
n = 20 # size of each signal
K = 50 # number of atoms in dict
T0 = 3 # number of non zero coefficients
Y = np.random.rand(n, N)
# Fit the model
KSVD_model = KSVD(K=K, T0=T0)
KSVD_model.fit(Y, verbose=True)
X, D = KSVD_model.X, KSVD_model.D
For images : (example in example_corrupted_image.py)
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from pyksvd.functions import train_ksvd_models, corrupt_image, reconstruct_image
# Define parameters
patch_size = 8
image_size = 256
K = 441 # number of atoms in dict
T0 = 10 # number of non zero coefficients
REMOVE_PIXELS_RATIO = 0.7
# Directories
train_dir = 'data/train/impressionism/'
test_image_path = 'data/test/impressionism/134.jpg'
# Train KSVD models
ksvd_models = train_ksvd_models(train_dir, patch_size, K, T0)
# Load test image
test_image = Image.open(test_image_path)
test_image = test_image.resize((image_size, image_size))
test_image_array = np.array(test_image, dtype=np.float32) / 255.0
# Corrupt image
corrupted_image, mask = corrupt_image(test_image_array, REMOVE_PIXELS_RATIO)
# Reconstruct image
reconstructed_image = reconstruct_image(corrupted_image, ksvd_models, patch_size)
References
@article{Aharon2006KSVD,
title = {K-SVD: An Algorithm for Designing Overcomplete Dictionaries for Sparse Representation},
author = {Aharon, Michal and Elad, Michael and Bruckstein, Alfred},
year = {2006},
journal = {IEEE Transactions on Signal Processing},
}
Metadata
Release files for pyksvd 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyksvd-0.1.3.tar.gz | 6.7 kB | Without provenance | Details for pyksvd-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyksvd-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for pyksvd-0.1.3-py3-none-any.whl |
Total release size: 14.0 kB
Release files / pyksvd-0.1.3.tar.gz
| Download URL | pyksvd-0.1.3.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
248fc01bf0c87d801440db1668afb4e433de49012172c0e9010b525461f6f4ae
|
|
BLAKE2b-256 checksum How to use checksums |
e3c1e211549e68e161759baf90d90f73616ad16167262537d220f40e260bc951
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.4
|
Release files / pyksvd-0.1.3-py3-none-any.whl
| Download URL | pyksvd-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c20f55eddc555de02981bfc82f8e15d142f524d7e7078ffec4fbd92f668be4f4
|
|
BLAKE2b-256 checksum How to use checksums |
4260f8964195adf5b8516e07a3407bbe630e057aac76830116eb1ff07390931f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.4
|
Security for pyksvd 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.