MATLAB is a powerful tool for analysing images and signals for developing applications. One of the applications of image compression with MATLAB using a graphical user interface is described in this article.

fig 1
Fig. 1: Flowchart showing the compression process

Cameras are nowadays being provided with more and more megapixels to improve the quality of captured images. With improvement in image quality, size of the image file also increases.

Due to speed limitation of the Internet, it takes more time to upload good-quality images that are of bigger sizes. A user needs to compress the image without degrading its quality. Mobile manufacturers need algorithms in their cameras that enable storing the images in reduced sizes without degrading their quality.

There are two types of compression algorithms, namely, loss-less and lossy-image compression. This article proposes a technique to compress the captured image to reduce its size while maintaining its quality. A number of images were considered to check the veracity of the proposed algorithm.

fig 2
Fig. 2: Original image sample 1

In this article, discrete cosine transform algorithm is used, which compresses the image with a good compression ratio.

The flowchart of the process is shown in Fig. 1.

The image is read through MATLAB to capture its pixels. After obtaining the compressed image, peak-signal-noise ratio (PSNR) and mean-square error (MSE) are calculated using the following relationships:


where m and n are the number of rows and columns. Image1 and Image2 are the original and compressed images, respectively.

fig 3
Fig. 3: MATLAB implementation of image sample 1
fig 4
Fig 4: Original image sample 2

After compression, there should not be much change in the quality of the image. MSE indicates an error between the original image and compressed image. It should be as small as possible.

Want a Mooshimeter Multimeter?

where R is the maximum fluctuation in the input image data type (maximum possible pixel value of image). PSNR is related to MSE and it gives the amount of noise in a compressed image. PSNR should be as high as possible.


All equations are implemented in MATLAB in the form of functions.

fig 5
Fig. 5: MATLAB implementation of image sample 2

Some images and their associated MATLAB graphical interfaces are shown in Figs 2 to 5.

Download source code: click here

Lalit G. Patil is a lecturer in Department of Electrical Engineering, M.S. University of Baroda, Gujarat. His areas of research include signal processing, image processing and control systems


  1. What should I do to compress whole video once I convert it in to frames?
    Can I get some guidance about video compression please…….
    Thank You

    • Here’s the reply from author Lalit Patil:
      Yes, Write a “for Loop” code to compress frames one by one. When complete compression of frames is done then merge frames into video. It will be compressed video.

  2. Sir…i also want to do the compression process for a video….please help me…also i need the decompression code also…

  3. can u give methe simulink of this project?
    its dynamic model equation?
    transformation eqn wrt transfer func
    stability of function
    error calculation
    root locus plots


Please enter your comment!
Please enter your name here