evgenyneu / image_compressor_c

An image compressor program written in C that uses singular value expansion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An image compression program written in C

This is a C program I wrote for fun to apply linear algebra theory I learned in Monash uni. The code uses singular value expansion method to reduce the size of an image. Here are compression results, featuring my cat Marmite.

Video of the compressed image Image compressed using single value expansion

Setup (MacOS or Linux)

1. Install GCC

In order to compile the program, you will need GCC, the C language compiler. Check if it's installed with the command that prints its version:

gcc -v

If you get an error, install GCC on your system.

2. Install OpenBLAS library

Follow these instructions to install OpenBLAS library.

3. Download the source code

Next, download the source code of the compressor (requires git):

git clone https://github.com/evgenyneu/image_compressor_c.git
cd image_compressor_c

4. Build the program

Finally, build the program:

make

This will create the executable file /build/compressor.

Usage

Compress an image file marmite.jpg using ten terms of the singular value expansion and five iterations of the power method:

./build/compressor --terms=10 --iterations=5 marmite.jpg compressed.jpg

It creates an image named compressed.jpg that looks like this:

Singular value expansion compression with 10 terms

You can experiment with the --terms and --iterations options and see how it affects the image quality and compression ratio.

Available options

compressor [--help] [--terms=10] [--iterations=5] IMAGE OUTPUT

IMAGE :  path to the image to compress
OUTPUT :  path to the compressed image that will be created
--terms :  number of terms in the singular value expansion
--iterations :  number of iterations of the power method
--notext :  no annotation on the image
--benchmark :  run the benchmark to measure compression performance,
               no other options are needed for the benchmark
--help :  show this message

Run unit tests

make test

The unlicense

This work is in public domain.

Compression results

Original uncompressed image

Uncompressed image

Compressed images

1 term compression

2 term compression

3 term compression

4 term compression

5 term compression

6 term compression

7 term compression

8 term compression

9 term compression

10 term compression

11 term compression

12 term compression

13 term compression

14 term compression

15 term compression

16 term compression

17 term compression

18 term compression

19 term compression

20 term compression

25 term compression

30 term compression

35 term compression

40 term compression

45 term compression

50 term compression

60 term compression

70 term compression

80 term compression

90 term compression

100 term compression

120 term compression

150 term compression

180 term compression

200 term compression

300 term compression

400 term compression

500 term compression

About

An image compressor program written in C that uses singular value expansion

License:The Unlicense


Languages

Language:C 97.2%Language:Makefile 2.8%