Coder Social home page Coder Social logo

labibdotc / image_compression_decompression Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 718 KB

Algorithm compresses image by taking diagonal averages of pixels and storing every four pixels in one pixel which reduces size significantly. Most images tested don't lose more than 2%. Decompression algorithm implemented too. Have fun trying it with the display in a ssh -X. Make sure you install X-quartz :)

C 95.37% Makefile 3.57% Shell 1.07%
bit-manipulation bit-shifting data-compression discrete-cosine-transform memory-management ppm-image rgb-reconstruction

image_compression_decompression's Introduction

Image compression and decompression algorithm

Algorithm compresses image by taking diagonal averages of pixels and storing every four pixels in one pixel which reduces size significantly. Most images tested don't lose more than 2%. Decompression algorithm implemented too. Have fun trying it with the display in a ssh -X. Make sure you install X-quartz :) Screenshot 2023-01-28 at 7 22 30 PM Screenshot 2023-01-28 at 7 22 18 PM Screenshot 2023-01-28 at 7 22 12 PM

Plan

Step 1: 12 bytes to RGB integers:

  • input: image file
  • output: array of rgb
  • no data loss

Step 2: RGB integers to floats:

  • input: RGB integers in form of array of structs
  • output: RGB floats i.e. each integer's ratio to maximum value of rgb in the picture
  • no data loss

Step 3: RGB floats to color space

  • input: RGB floats
  • output: color space structs Y, Pb, Pr i.e. in floating point form
  • Formula for output: y = 0.299 * r + 0.587 * g + 0.114 * b; pb = -0.168736 * r - 0.331264 * g + 0.5 * b; pr= 0.5 r-0.418688g-0.081312*b;
  • data loss: float x float produces trailing decimals that would eventually get lost after the floating 7 point place.

Step 4: color space to DCT space

  • input: color space structs
  • output: a struct containing Pb, Pr, a, b, c, and d -> 1/4 the amount of the color space structs
  • Formula for the output a=(Y4 +Y3 +Y2 +Y1)/4.0; b = (Y4 + Y3 − Y2 − Y1)/4.0; c = (Y4 − Y3 + Y2 − Y1)/4.0; d = (Y4 −Y3 −Y2 +Y1)/4.0;
  • data loss: averaging out every 4 pixels into 1 would yield in minor data loss

Step 5: b, c and d to scaled ints

  • input: b, c, and d in float from
  • output: scaled ints in 5-bit scaled ints
  • data loss: data is lost as values are truncated at 0.3 and -0.3

Step 6: load bits into words

  • input: size reduced uarray with 32-bit representation (9-a, 5-b, 5-c, 5-d, 8-pb and 8-pr) for every 4 pixels
  • output: one 32 bit word that has all the data for a given 4-pixel
  • data loss: no data loss

Step 7: write to disk compressed image

Architecture

Decompression happens by reversing every step in the same file it was compressed.

image_compression_decompression's People

Contributors

labibdotc 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.