Skip to content

nhauber99/degradr

Repository files navigation

degradr

Python library for realistically degrading images.

A blog post explaining the theory behind it a bit more can be found here.

The Demo.py file provides an example usage of the library and should degrade the included test image if you set up everything correctly.

For building the Intel Integrated Performance Primitives Python wrapper, which is needed for demosaicing, please download the IPP libraries (or the whole oneAPI Base Toolkit). Then adapt the additional library and include directories of the Visual Studio project to point to the targeted python version and compile as a Release x64 library. Copy the PyIPP.pyd file somewhere into your pythonpath / adapt the pythonpath (more info in this issue thread: #2). When running into trouble, this guide might help which is what I used for creating the wrapper library. If building on Linux, you're unfortunately on your own, but it should absolutely be doable as well.

The set of matrices for conversions between the camera and sRGB color space was derived from the LibRaw library and does NOT fall under the license of this project.

A sample usage of the library can be found in the Test.py script, which applies all steps necessary for degrading a "perfect" image. Before that, you'll need to run the ZernikePSF.py and PrepKernels.py script to prepare the convolution kernels. The applied steps are as follows (assuming the image is already in the camera color space):

  1. Convert the input image to the assumed camera color space if needed.
  2. Convolve by random blur kernel. (a combination of defocus blur, gaussian blur, PSFs generated from Zernike polynomials to model the lens aberrations, chromatic aberration)
  3. Color filter array (in practice applied directly before the demosaicing for simplicity, but this doesn't affect the output)
  4. Poison noise
  5. Gain
  6. Read Noise
  7. Quantization
  8. Camera white balance
  9. Demosaicing (3 different methods using the Intel Integrated Performance Primitives)
  10. Color space transformation (from white balance corrected camera color space to sRGB)
  11. JPEG Compression


Examples:

Input Image
Blur Image
Blur
Noise
Image
Blur
Noise
CFA
Image
Blur
Noise
CFA
AHD Demosaicing
Image
Blur
Noise
CFA
AHD Demosaicing
JPEG Compression
Image