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.
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.
Follow these instructions to install OpenBLAS library.
Next, download the source code of the compressor (requires git):
git clone https://github.com/evgenyneu/image_compressor_c.git
cd image_compressor_c
Finally, build the program:
make
This will create the executable file /build/compressor
.
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:
You can experiment with the --terms
and --iterations
options and see how it affects the image quality and compression ratio.
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
make test
This work is in public domain.