Experimental image compressor using parts of JPEG standard written in Python using Pillow, Numpy and cv2 libraries. Uses the YCoCg color model, default chroma subsampling is 4:2:0 and the DCT quantization table is the same as JPEG (MIMG uses the same quantization table for luma and color channels).
This is how the algorithm performs on photos: Test image source
The same photo compressed using MIMG
Detailed view of resulting macroblocks compared to JPEG (q=35):
Basic MIMG compression statistics:
Note: the higher the compression ratio, the better.
| image | raw (KiB) | mimg (KiB) | compression ratio |
|---|---|---|---|
| gradient-01 | 3 072 | 4.5 | 689.6 |
| gradient-02 | 6 075 | 1.2 | 4894.4 |
| gradient-03 | 6 075 | 8.1 | 747.2 |
| photo-01 | 1 882 | 46.1 | 40.9 |
| photo-02 | 7 178 | 334.4 | 21.5 |
| photo-03 | 6 958 | 351.3 | 19.8 |
| photo-04 | 114 413 | 3 066.2 | 37.3 |
| photo-05 | 81 154 | 2 293.4 | 35.4 |
| photo-06 | 17 625 | 363.3 | 48.5 |
| render-01 | 6 075 | 92.9 | 65.4 |
| render-02 | 6 075 | 84.2 | 72.1 |
| render-03 | 24 300 | 74.5 | 326.2 |
| render-04 | 18 432 | 234.4 | 78.6 |
| test-pattern-01 | 6 075 | 2.1 | 2916.5 |
| test-pattern-02 | 6 075 | 0.9 | 6624.9 |
| test-pattern-03 | 6 075 | 4.7 | 1292.8 |
| ui-01 | 6 075 | 49.2 | 123.5 |
| ui-02 | 6 075 | 82.3 | 73.8 |
| ui-03 | 2 243 | 67.1 | 33.4 |
MIMG compression comparison vs JPEG(q=35) and PNG:
| image | compression ratio | comparison | ||||
|---|---|---|---|---|---|---|
| MIMG | JPEG | PNG | vs JPEG | vs PNG | ||
| gradient-01 | 689.6 | 117.4 | 19.2 | +487% | +3491% | |
| gradient-02 | 4894.4 | 132.7 | 718.5 | +3589% | +581% | |
| gradient-03 | 747.2 | 149.6 | 103.4 | +399% | +622% | |
| photo-01 | 40.9 | 46.7 | 2.3 | -13% | +1677% | |
| photo-02 | 21.5 | 24.0 | 1.5 | -10% | +1344% | |
| photo-03 | 19.8 | 21.6 | 1.4 | -8% | +1317% | |
| photo-04 | 37.3 | 41.7 | 1.9 | -11% | +1881% | |
| photo-05 | 35.4 | 52.2 | 1.7 | -32% | +1958% | |
| photo-06 | 48.5 | 52.8 | 1.9 | -8% | +2427% | |
| render-01 | 65.4 | 71.2 | 3.4 | -8% | +1806% | |
| render-02 | 72.1 | 69.0 | 3.7 | +5% | +1845% | |
| render-03 | 326.2 | 144.6 | 4.3 | +126% | +7436% | |
| render-04 | 78.6 | 70.2 | 11.0 | +12% | +615% | |
| test-pattern-01 | 2916.5 | 143.1 | 707.5 | +1937% | +312% | |
| test-pattern-02 | 6624.9 | 178.4 | 721.9 | +3613% | +818% | |
| test-pattern-03 | 1292.8 | 174.0 | 516.5 | +643% | +150% | |
| ui-01 | 123.5 | 71.0 | 76.9 | +74% | +61% | |
| ui-02 | 73.8 | 39.5 | 39.5 | +87% | +87% | |
| ui-03 | 33.4 | 29.2 | 9.9 | +14% | +237% | |
Basic usage:
from mimg import MImg
img = MImg.from_image("image.png") ## open image using Pillow library
img.save("image.buf") ## save (and compress) in MImg format
img = MImg.open("image.buf") ## open (and decompress) image in MImg format
img._image.show() ## view the image

