Image compression codec for 16 bit medical images

MIC - Medical Image Codec

This library introduces a lossless medical image compression codec MIC for 16 bit images which provides compression ratio similar to JPEG 2000 but with much higher speed of compression and decompression.

Branch Status
main example workflow

Compression Algorithm

The compression algorithm uses a combination of Delta Encoding, RLE and Huffman Coding or Finite State Entropy (FSE) to achieve the best compression and get best performance. By tweaking each of the algorithms to efficiently function on 16 bit greyscale medical images we have achieved good compression with very good decompression speed.

Delta Encoding

The delta encoding implementation encodes the difference between current pixel and average of top and left pixel. If the difference is greater than a threshold then we encode the pixel value directly preceded by a delimiter.

Based on the pixel depth of an image, which is determined by the maximun pixel value, the threshold and delimiter for delta encoding are determined.

RLE

The RLE algorithm encodes runs of similar or different values by putting the run count followed by the values. Each run length is of minimum length of 3. This is done because it guarantees that the RLE encoded data is never longer than the original.

The similar and different runs are distinguished by ensuring that the run value of similar runs is positive and the run value for dis-similar values is negative. If we don’t want the values to be negative then we can also choose a constant value, where any run value less than this constant is considered to be for similar runs and any value greater than this constant is considered for dis-similar values. In our implementation we choose this constant, called MidCount, based on the max value pixel of the image.

Huffman Encoding

Huffman encoding of the values is done by first constructing a huffman tree out of the input values. As we are encoding 16 bit alphabet it has a potential of having high number of symbols (2^16).

To prevent a large huffman table we restrict the number of symbols. We only consider the most highly occurring symbols for constructing the huffman tree.

We iteratively select the symbols which gives us a tree with maximum depth of 14. (Old Approach: A maximum of 500 unique symbols and only symbols whose occurrence frequency is more then 1/200 of the occurrence frequency of most frequent symbol are chosen.)

This ensures that the tree length is limited and speeds up the encoding and decoding process. It also saves space as we have to save the huffman tree with the encoded values. Canonical huffman codes are used for construction of the huffman table (codebook) which ensures that the constructed table is most compact and efficient for encoding and decoding.

During the encoding process we add a delimiter before each symbol which is also part of the huffman table. The delimiter is chosen based on the max pixel value of the image.

FSE

The Finite State Entropy algorithm implementation from https://github.com/klauspost/compress has been re-written for 16 bit dataset.

Similar Resources

A Free 8-Bit Sprite Generator. Create 256 variants from a single template .PNG

A Free 8-Bit Sprite Generator.  Create 256 variants from a single template .PNG

BitSprite A Free 8-Bit Sprite Generator. What? BitSprite is a program that creates variants of an image across total sprite sheet of the resultant ima

Sep 20, 2022

Read and write Netpbm images from Go programs

netpbm Introduction netpbm is a package for the Go programming language that implements image decoders and encoders for the Netpbm image formats. The

Dec 29, 2022

Pure Golang Library that allows simple LSB steganography on images

Pure Golang Library that allows simple LSB steganography on images

Steganography Lib Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decodi

Dec 22, 2022

Resize images and animated GIFs in Go

Lilliput relies on mature, high-performance C libraries to do most of the work of decompressing, resizing and compressing images. It aims to do as little memory allocation as possible and especially not to create garbage in Go. As a result, it is suitable for very high throughput image resizing services.

Jan 3, 2023

Reproducing images with geometric primitives.

Reproducing images with geometric primitives.

Primitive Pictures Reproducing images with geometric primitives. How it Works A target image is provided as input. The algorithm tries to find the sin

Dec 31, 2022

Fast and secure standalone server for resizing and converting remote images

imgproxy imgproxy is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, sp

Jan 1, 2023

An iterative algorithm to generate high quality triangulated images.

An iterative algorithm to generate high quality triangulated images.

Triangula uses a modified genetic algorithm to triangulate images. It works best with images smaller than 3000px and with fewer than 3000 points, typically producing an optimal result within a couple of minutes.

Jan 8, 2023

A go library for reading and creating ISO9660 images

iso9660 A package for reading and creating ISO9660, forked from https://github.com/kdomanski/iso9660. Requires Go 1.13 or newer. Joliet and Rock Ridge

Mar 4, 2021

Generate high-quality triangulated art from images.

Generate high-quality triangulated art from images.

An iterative algorithm to generate high quality triangulated images.

May 26, 2021
Comments
  • Simple improvements

    Simple improvements

    Hi!

    Instead of having a pure left predictor you can try left+up

    			if x > 0 {
    				prevSymbol = int32(in[index-1])
    			}
    			if y > 0 {
    				prevSymbol = (prevSymbol + int32(in[index-width])+1)/2
    			}
    

    (changes to decompression are similar)

    This improves compression:

    BenchmarkDeltaZZRLEFSECompress/MR-32 	    1220	    960593 ns/op	 136.45 MB/s	         2.199 ratio
    BenchmarkDeltaZZRLEFSECompress/MR-32 	    1148	   1014561 ns/op	 129.19 MB/s	         2.349 ratio
    
    BenchmarkDeltaZZRLEFSECompress/CR-32 	      21	  49143662 ns/op	 153.28 MB/s	         3.530 ratio
    BenchmarkDeltaZZRLEFSECompress/CR-32 	      21	  51905910 ns/op	 145.12 MB/s	         3.754 ratio
    
    BenchmarkDeltaZZRLEFSECompress/XR-32 	      16	  67411862 ns/op	 156.58 MB/s	         1.695 ratio
    BenchmarkDeltaZZRLEFSECompress/XR-32 	      16	  71091406 ns/op	 148.48 MB/s	         1.756 ratio
    
    BenchmarkDeltaZZRLEFSECompress/MG1-32         	      31	  38481226 ns/op	 254.89 MB/s	         8.554 ratio
    BenchmarkDeltaZZRLEFSECompress/MG1-32         	      28	  41851546 ns/op	 234.36 MB/s	         8.880 ratio
    
    BenchmarkDeltaZZRLEFSECompress/MG2-32         	      31	  38487303 ns/op	 254.85 MB/s	         8.540 ratio
    BenchmarkDeltaZZRLEFSECompress/MG2-32         	      27	  41595096 ns/op	 235.81 MB/s	         8.869 ratio
    

    The reason is mostly that the predictor is cleaned more from noise.

    On x == 0 && y >1 you could also use pure up prediction for a small additional gain.

    Furthermore you could also look into "Paeth" filtering, as used by PNG. In most cases this is even more efficient.

Image - This repository holds supplementary Go image librariesThis repository holds supplementary Go image libraries

Go Images This repository holds supplementary Go image libraries. Download/Insta

Jan 5, 2022
Simple image compression using SVD

SVD image compression An implementation image compression using SVD decomposition on Go Built With Go 1.17 Gonum Compression examples Header Image Ori

Mar 30, 2022
H265/HEVC HM Video Codec in Go

GoHM H.265/HEVC HM Video Codec in Go Release Note: +v1.0.b03092013 -fix multiple bugs in decoder +v1.0.b03032013 -Initial release candidate for GoHM 1

Nov 8, 2022
A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.
A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.

go-bmppath Overview Package bmppath converts a monochrome 1-bit bitmap image into a set of vector paths. Note that this package is by no means a sophi

Mar 22, 2022
Pbm - Package ppm implements a Portable Bit Map (PBM) image decoder and encoder written in Go

Package pbm import "github.com/slashformotion/pbm" Package pbm implements a Portable Bit Map (PBM) image decoder and encoder. The supported image col

Jan 5, 2022
Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket

Features Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket Environment Variables IMAGE_SIZES - formax 200x20

Feb 2, 2022
darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.
darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.

Darkroom - Yet Another Image Proxy Introduction Darkroom combines the storage backend and the image processor and acts as an Image Proxy on your image

Dec 6, 2022
Easily customizable Social image (or Open graph image) generator

fancycard Easily customizable Social image (or Open graph image) generator Built with Go, Gin, GoQuery and Chromedp Build & Run Simply, Clone this rep

Jan 14, 2022
An API which allows you to upload an image and responds with the same image, stripped of EXIF data

strip-metadata This is an API which allows you to upload an image and responds with the same image, stripped of EXIF data. How to run You need to have

Nov 25, 2021
Imgpreview - Tiny image previews for HTML while the original image is loading
Imgpreview - Tiny image previews for HTML while the original image is loading

imgpreview This is a Go program that generates tiny blurry previews for images t

May 22, 2022