Lossy Image Compression: DCT

In the last few blog posts, I introduced a new image compression algorithm. This algorithm uses a modified version of the discrete cosine transform (DCT). The basic idea behind this algorithm is to group pixels into 8×8 blocks, and then use the DCT to convert each block into 64 frequency coefficients. Most of the coefficients in each block will be very low, so we can set them all to zero without significant loss of data. Then we take only the high frequency coefficients (the ones that are still non-zero) and store them in an efficient data format. In order to reconstruct the image later on, we take the stored coefficients and apply an inverse DCT to each block. This brings us back to the original image, except that since we threw away most of the coefficients, it will be slightly blurry or pixelated.

The above description is an oversimplification; I’ve skipped over several details. To see how this actually works, you’ll need to read through my previous blog posts:

Image Compression Algorithm: The Basics (this post)

Image Compression Algorithm: Frequency Coefficients

Image Compression Algorithm: Improving Performance with Lookup Tables

Image Compression Algorithm

On my quest to find a file compression algorithm to compress images and reduce the size of bitmaps I came across this website. It’s a great resource for anyone looking for information on how to implement an image compression algorithm into code. This site is aimed at people who have some knowledge of programming, but don’t necessarily know their way around algorithms.

Image compression can come in many different forms. This website outlines the simple and more complex methods, and explains what they are used for and why they are used. It also provides information on when each algorithm should be used, and gives you an idea of what is available in the world of image compression.

It starts off with an article on the basic principles of image compression, which includes things like JPEG, GIF, PNG and TIFF files. Then it goes into detail about the more complex algorithms that are used, such as Huffman coding and arithmetic coding. The explanations are clear and easy to understand, even if you aren’t familiar with the subject matter. If you aren’t sure what each algorithm does, or why it is better than another one, then this site will help you out a lot. Even if you do know all about algorithms, it is still worth checking out this site for all the extra information it contains about

When we compress an image, we take a picture and store it in a way that takes up less space. There are many ways to compress an image, but in this blog, we’re going to focus on how to do this with the least amount of loss of quality. This is by no means an easy task and there are many ways to go about it.

In order to make this blog as accessible as possible, we’re going to use Python for our implementation. If you don’t have too much experience with coding, I’ve included some links at the bottom of this blog explaining how to get started with Python. We will also try and make sure that the code is as simple as possible so that we can focus on the theory behind image compression.

Image compression is the application of Data Compression on digital images. In effect, the objective is to reduce redundancy of the image data in order to be able to store or transmit data in an efficient form.

There are different ways to do this kind of compression, and depending on the parameters you change, you get a different result. There are also different types of compression, which we will discuss in a bit. The main idea behind image compression is that parts of a picture/image can be predicted from other parts. For example, imagine a black and white image with alternating black and white pixels:

The pixels here are stored as bits (1 = black, 0 = white) and this alternating pattern can be described by: 1 0 1 0 1 0 1 0 … etc. If we want to compress the image, one way we could do it is by describing that pattern with less data than it would take to describe each pixel individually. This is known as lossless compression, because when decompressing all of the original data can be recovered exactly. Lossless compression attempts to find redundant information and remove it without losing any information at all.

Another approach is lossy compression, which doesn’t attempt to recover all of the original data like lossless

Image compression is a type of data compression applied to digital images, to reduce their cost for storage or transmission. Algorithms may take advantage of visual perception and the statistical properties of image data to provide superior results compared with generic data compression methods which are used for other digital data.

Image compression can be lossy or lossless. Lossless compression is preferred for archival purposes and often for medical imaging, technical drawings, clip art, or comics. Lossy compression methods, especially when used at low bit rates, introduce compression artifacts. Lossy methods are typically suitable for natural images such as photographs in applications where minor (sometimes imperceptible) losses of fidelity may be acceptable to achieve a substantial reduction in bit rate. Lossy compression that produces negligible differences may be called “visually lossless”. The selected colors are specified in the color palette in the header of the compressed image. Each pixel just references the index of a color in the color palette, this method can also be combined with dithering to avoid posterization. It is frequently used as web site images, creating smaller but higher quality files than a full-color bitmap. The format supports up to 8 bits per pixel thus allowing a single image to reference its own palette of up to 256 different colors chosen from

I was really looking into image compression as a practice project for my studies and decided to choose a subject which is not well known and tried to write about it. I picked an algorithm which is used in some image formats, so i am not going to reinvent the wheel but I wanted to get a better understanding of what is actually going on there.

The algorithm is called Run-length Encoding and it can be applied to lossless or lossy compression. The algorithm is based on the idea that runs of similar data can be represented in a shorter way than every single data itself.

So let’s assume you have an image with eight lines, each containing eight pixels with only two colors, black and white. So your uncompressed data might look like this:

11111111 11111111 11100111 11110011 11001100 11000011 11000011 11110011

The image compression algorithm is the process of reducing the amount of data required to represent a digital image. The objective of the compression is to reduce redundancy and irrelevancy.

There are two types of compression algorithms: Lossless and lossy. Lossless compression algorithm reduces bits by identifying and eliminating statistical redundancy. Lossy compression algorithm reduces bits by identifying unnecessary information and removing it.

Lossless Compression