<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thushara Bandara on Medium]]></title>
        <description><![CDATA[Stories by Thushara Bandara on Medium]]></description>
        <link>https://medium.com/@thusharabandara?source=rss-c7b989ac3cbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RdP_i5oSGuVN0WhiLCVv8g.jpeg</url>
            <title>Stories by Thushara Bandara on Medium</title>
            <link>https://medium.com/@thusharabandara?source=rss-c7b989ac3cbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:22:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thusharabandara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Measure the Compression Performance of an Image Compression Algorithm]]></title>
            <link>https://medium.com/@thusharabandara/measure-the-compression-performance-of-an-image-compression-algorithm-ea68c1839ec6?source=rss-c7b989ac3cbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea68c1839ec6</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[compression]]></category>
            <category><![CDATA[performance-metrics]]></category>
            <dc:creator><![CDATA[Thushara Bandara]]></dc:creator>
            <pubDate>Tue, 14 Sep 2021 04:35:57 GMT</pubDate>
            <atom:updated>2021-09-14T04:47:07.756Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RD8eokfdZPXFm-FGCxcXWA.png" /><figcaption>Figure 1. Variations of Lena image based on different compression ratios</figcaption></figure><p>The rapid development of fields such as multimedia and image processing results in the creation of high-quality images and videos with fine details. Therefore, file sizes of those multimedia components are usually large. When storing them on persistent memory, it takes more space. On the other hand, a high bandwidth is needed for transmitting them from one place to another over the internet. That is why theories such as image compression and video compression were introduced into the world.</p><p>In simple terms, image compression is a process of reducing the file size of an image using an algorithm, which we are called image compression algorithms such as JPEG (Joint Photographic Experts Group). More technically, the term “compress” is also known as “encode”, which is the representation we get after reducing the file size; also, in order to see the picture in one piece, we need to convert it into its decompressed form, also known as encoded representation. In this article, I am not going to discuss any of those theories and algorithms in detail, and only focusing on how to evaluate the performance of those algorithms in terms of various measuring components.</p><p>When measuring the performance of an image compression algorithm, the main concern would be to focus on the file size of the encoded representation and how better it constructs the decoded image from its encoded representation. Depending on that compression algorithms can be classified into two categories, namely lossy compression and lossless compression. As the compression behavior depends on the irrelevance and the redundancy of image pixels, it is difficult to measure the overall performance of such an algorithm in general.</p><p>This discussion is entirely based on one of my research findings related to image compression, entitled “<a href="https://www.researchgate.net/publication/339738072_Deep_Autoencoder-Based_Image_Compression_using_Multi-Layer_Perceptrons">Deep Autoencoder-based Image Compression using Multilayer Perceptrons</a>”, which clearly explains the most relevant measuring components that can be used in measuring the performance of an image compression algorithm. In this article, we will discuss each component briefly along with their mathematical functions and their Python implementations, which have an enormous value if you are planning to do research in the domain of data compression, especially, in image compression.</p><p>Let’s clear up one at a time.</p><h3>Compression Time (CT)</h3><p>It is the time taken for both compression and decompression processes. When the compression and decompression times are at an acceptable level, it implies that the corresponding algorithm is adequate in terms of the time factor. This factor varies from machine to machine in terms of the performance of their hardware components.</p><p>Also, the compression time is also affected by the time complexity of a compression algorithm. Even with cheap hardware resources, the compression and decompression times can be maintained at a very low level using an optimal implementation.<strong> </strong>In the context of image processing, we need to compute both compression and decompression times as the execution time of the algorithm. Let’s see how we can implement it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/809dec717d0f226e9f74fee9d3056d26/href">https://medium.com/media/809dec717d0f226e9f74fee9d3056d26/href</a></iframe><h3><strong>Compression Ratio (CR)</strong></h3><p>The compression ratio is another important measuring component, which is more common than other measures. It is the ratio between the size of the compressed (encoded) image and the size of the original image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfftNzcSfDnfGmXqkRzI5A.png" /><figcaption>Equation 1. The compression ratio</figcaption></figure><p>The below code clearly demonstrates how the implementation can be done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb74791d83fa9f1df1aad562219162eb/href">https://medium.com/media/cb74791d83fa9f1df1aad562219162eb/href</a></iframe><h3><strong>Compression Factor (CF)</strong></h3><p>It is the inverse of the compression ratio, which is the ratio between the size of the original image and the size of the compressed image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aI73wuJPN0NBrGqoFfs9dA.png" /><figcaption>Equation 2. The compression factor</figcaption></figure><p>As you have already learned about the implementation for compression ratio, understanding the below code for compression factor is effortless.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a652c8f78471ba8f3d53b1d8c2bdfe4b/href">https://medium.com/media/a652c8f78471ba8f3d53b1d8c2bdfe4b/href</a></iframe><h3><strong>Mean Squared Error (MSE)</strong></h3><p>Compression of an image using a lossy image compression algorithm result in a decompressed image with loss of some information of the pixel intensity values. Those pixels are significantly different than the original image pixels. The error metrics that can be used to compare the original image and the decompressed image is MSE. It calculates the cumulative squared error between each corresponding pixel in the original and the decompressed image. The MSE is defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tqk3386e_cz1RlkPERwLzg.png" /><figcaption>Equation 3. The mean squared error</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yzv_wkmgQF43_JK6-NKPBQ.png" /></figure><p>Although the equation seems a bit confusing, the implementation is easy to understand if you could visualize each<strong> <em>I</em></strong> component as actual images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c893ede4f0bfebb7a3d5131311990f04/href">https://medium.com/media/c893ede4f0bfebb7a3d5131311990f04/href</a></iframe><h3><strong>Peak Signal to Noise Ratio (PSNR)</strong></h3><p>In image compression, the value of PSNR measures the ratio between the maximum possible intensity value (power) of an image (signal) and the power of distorting noise, which affects the quality of its representation as a logarithmic decibel scale. A higher PSNR value provides higher image quality and the other end of the scale, a smaller PSNR value implies high numerical differences between both the original image and the decompressed image. The PSNR is defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qD5_ZPevCYSpPEe2zgiwTA.png" /><figcaption>Equation 4. The peak signal to ratio</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlliejevauYHszZdRbWXgg.png" /></figure><p>The implementation for computing PSNR value is given as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/820ee362828080dca745869f0daf12b8/href">https://medium.com/media/820ee362828080dca745869f0daf12b8/href</a></iframe><h3><strong>Structural Similarity Index Measure (SSIM)</strong></h3><p>The SSIM is a well-known perceptual metric that quantifies the degradation of images. It needs two images from the same image capture as same as measuring PSNR. Unlike PSNR, SSIM is based on the visible structure in images and measure the similarity between the original image and the decompressed image. The formula of the SSIM is based on three comparison measurements between the samples of <em>x </em>and <em>y </em>is given by the equations below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHkl8Bs3x-DX6XP_Txot-g.png" /><figcaption>Equation 5</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGQz2zHYRU_oigESZUYrSw.png" /><figcaption>Equation 6</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Nz43c4Apt7nmJuR-LNrAw.png" /><figcaption>Equation 7</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FgJKkuiCGpR_91izC4GLmQ.png" /><figcaption>Equation 8</figcaption></figure><p>Then the SSIM can be calculated as a weighted combination of Equations 5, 6, and 7. The resultant value of the SSIM index is a decimal value between -1 and 1, and when the value is reached 1, the given original image and the decompressed image are identical. When the image compression algorithm is a lossy algorithm, the SSIM value is not equal to 1 but should be close to the value 1 for the acceptance of an algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qOOljjoBqTPjgAfJy8-NQ.png" /><figcaption>Equation 9. The structural similarity index measure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yu9KPg80N0BxwaUXEpfX-g.png" /></figure><p>In this case, you don’t have to worry about implementing this equation from scratch. Because there is an inbuilt function, namely <a href="https://scikit-image.org/docs/0.13.x/auto_examples/transform/plot_ssim.html"><strong>compare_ssim</strong></a>, available in <a href="https://scikit-image.org/"><strong>scikit-image</strong></a>, which is an open-source image processing library in Python. Below code descibes how the implementation can be done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c1e3975ca664a2d5913dbcd171f9c6b/href">https://medium.com/media/4c1e3975ca664a2d5913dbcd171f9c6b/href</a></iframe><p>We almost reached the end of this article. To wind up, first, we have discussed the introduction to image processing and its advantages in the real world. Then, we have discussed six measuring components along with their mathematical formulas and Python implementation.</p><p>I hope you enjoyed reading this. If you are really interested in image compression as much as I do, you can refer <a href="https://www.researchgate.net/publication/339738072_Deep_Autoencoder-Based_Image_Compression_using_Multi-Layer_Perceptrons">our paper</a> to get more understanding on the approach we used in our research.</p><p><strong>Reference:</strong></p><p>G.G.H.M.T.R. Bandara and R. Siyambalapitiya, “Deep Autoencoder-based Image Compression using Multilayer Perceptrons.” International Journal of Soft Computing and Engineering (IJSCE) Volume-9 Issue-6. Online: (Mar 2020) (<a href="https://www.researchgate.net/publication/339738072_Deep_Autoencoder-Based_Image_Compression_using_Multi-Layer_Perceptrons">source</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea68c1839ec6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>