Giter VIP home page Giter VIP logo

dct-coefficient-decoder's Introduction

DCT coefficient decoder

Python wrapper for decoding DCT coefficients from JPEG-compressed images.

Note: This is research code and has not been designed for use in production. Tested with Python 3.5 and libjpeg 9a.

Prerequisites

  • Header files for building Python extensions
apt-get install python3-dev
  • You need to have libjpeg installed. If you don't have a global installation, you can download libjpeg from here and install it by following the build instructions. Please update the include and lib paths in setup.py such that they point to your installation.
libjpeg_include_dir = "path/to/libjpeg/build/include"
libjpeg_lib_dir = "path/to/libjpeg/build/lib"
  • Python dependencies
pip install Cython numpy

Compile

Global installation

pip install .

This will automatically install the python dependencies.

Local installation

To compile the extension for use in the project's root directory, run the following:

python setup.py build_ext --inplace

This will place a shared object in the current working directory. For use from another directory, make sure to include this module in your PYTHONPATH.

Usage

from decoder import PyCoefficientDecoder 

filename = "image.jpg"

# Load and decode image
d = PyCoefficientDecoder(filename) 

# Access image width
d.image_width

# Read (quantized) DCT coefficients of luminance channel
d.get_dct_coefficients(0)

# Read quantization table for luminance channel
d.get_quantization_table(0)

Example how to vary the DCT implementation. Supported options are JDCT_ISLOW (default), JDCT_IFAST, JDCT_FLOAT.

from decoder import PyCoefficientDecoder, JDctMethod
filename = "image.jpg"
d = PyCoefficientDecoder(filename, dct_method=JDctMethod.JDCT_FLOAT)
img = d.get_decompressed_image()

Known issues

  • Attempting to read uncompressed image after reading DCT coefficients results in Improper call to JPEG library in state 210. Workaround: Initialize another instance of PyCoefficientDecoder.

Misc

  1. Another way to quickly read an image's quantization tables:
djpeg -verbose -verbose image.jpg > /dev/null
  1. A visual explanation of the Discrete Cosine Transform (DCT) is given in this notebook.

dct-coefficient-decoder's People

Contributors

alxshine avatar btlorch avatar

Watchers

 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.