Task 011: Lossless compression of B/W image

Your task is to implement lossless compression of two-color raster image (one bit per pixel), you should be focused on images with many thin lines/curves - scanned handwriting using a thin pen.


Entropy codec

There is a standard vocabulary-based entropy codec ready for you: DeflateStream (Zlib) or a more effective buffered version BufferedDeflateStream.


You will be using the 011compressionbw project from the grcis repository. The simple WinForms-based application is ready, user can load an input image and start encoding/decoding by pressing the button Recode. After a short time encoding and recoding will finish and you will be informed about results: time spent in encoding phase, size of intermediate binary file and number of pixel errors (this number should be zero as your codec should be lossless!).


Your task is to design and implement your own compression algorithm and check its "losslessness". The whole codec (encoder & decoder) will be implemented in one class BWCodec - in one source file BWCodec.cs.

Please ignore eventual input-image colors, read input data using Color.GetBrightness(). Put raster image size together with a magic number MAGIC into the header of your file-format.

Methods to implement: EncodeImage() and DecodeImage().


Predictive compression (e.g. 8-pixel neighborhood), some form of line-tracking, inter-line redundancy, vocabulary of little patterns (2x2px to 4x4px), quad-tree principle, ..

Comparison/benchmarking: compression in PNG format or specialized TIFF - Fax 4 (the later one is very good, don't be intimidated by it, you don't need be such good).


Due to: 7. 1. 2018


Base: 25 points (functional code, has to be lossless!), bonus points for interesting idea and efficiency (contest).


Visual Studio project: 011compressionbw.

Source file

Modify and submit the file: BWCodec.cs
Return your name in the InitParams() function!

Results / contest

Result page.

Input data

TEST DATA: there is one image in the repository: santa.png (but it doesn't match our criteria very well), more images: zadani1.png (1393x689), lukas1.png (909x451), lukas2.png (1294x900), masa2.png (1372x1075), handwr03.png (1152x749), hodnoceni.png (1301x910), bad.png (500x357).

Copyright (C) 2010-2018 J.Pelikán, last change: 2018-01-21 05:57:04 +0100 (Sun, 21 Jan 2018)