Git Product home page Git Product logo

quant's Introduction

quant

Quantization based lossy data compression

This is implementation of VQ algorithm as in http://www.data-compression.com/vq.shtml.

Here is another nice link explaining the concept http://www.gamasutra.com/view/feature/131499/image_compression_with_vector_.php

Examples

Before compression After compression
488K, PNG 92K, Quant, 2,9 bits per pixel
388K, PNG 92K, Quant, 2,9 bits per pixel
108K, PNG 32K, Quant, 4 bits per pixel
84K, PNG 32K, Quant, 4 bits per pixel

All of the above images have compression ratio between 15% and 20% compared to 24-bit per pixel image, and 1:2,5 to 1:5 ratio compared to PNG. Above images are being run with 2x2 block and 1024 codevectors, since experimental results showed that these give reasonable compression ratio, time and image quality.

Algorithm details

In order to get yourself familiarized with this algorithm description I recommend reading articles: http://www.data-compression.com/vq.shtml, http://www.gamasutra.com/view/feature/131499/image_compression_with_vector_.php.

Algorithm splits image into blocks of given size (default is 2x2) and then converts the blocks to vectors. Every pixel is considered to be 3x1 vector, and blocks are based on pixels, so 2x2 block (4 pixels) is transformed to 12 dimensional vector. Pixel values range from [0, 255], and this is scaled to [0, 1] range (this gives slightly better results), so in the end we receive 12-dimensional vector.

Splitting method is used to find codevector. I start with one codevector being average of all vectors and in each iteration I run LBG algorithm to improve the codevector base, after LBG run number of codevectors is doubled with first half being multiplied by (1+eps) and the other by (1-eps), and then again LBG is being executed on these. We repeat splitting phase until desired number of codevectors is achieved.

The problem of empty codevector region is solved by assigning random vector from area of the biggest distortion.

Possible improvements

There are numerous possible improvements I haven't been able to solve reasonably due to lack of time, experiments etc.

Building

Make sure you have cmake, gcc and boost libraries installed:

sudo apt-get install cmake gcc libboost-all-dev

Pick a directory and clone into it using:

git clone https://github.com/coodie/quant
cd quant

Time to build and install the project:

mkdir build
cd build
cmake ..
make -j
make install

In order to override compiler used by cmake

export CXX=/path/to/compiler
mkdir build
cd build
cmake ..
make -j

Usage

Currently only .ppm file compression is supported. Best way to get .ppm out of your favourite format is to use Netpbm package, it is usualy installed on most of linux distros. Here are examples how to get .ppm file from .png and .jpg.

pngtopnm file.png > file.ppm
jpegtopnm file.jpg > file.ppm

Quant performs operations on files based on their extension:

Compression:

quant input.ppm -o output.quant

Decompression:

quant input.quant -o output.ppm

Showcase (how file looks like after compression):

quant input.ppm -o output.ppm

For more options (playing with parameters) use:

quant --help

quant's People

Contributors

coodie avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

quant's Issues

Write by bits to file

Current implementation rounds bits to bytes and then writes bytes to file (it's easier). Better compression can be achieved by writing by bits, although it's way much harder to implement.

Add different algorithm

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.