View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
JPEG Compression (DCT)

3.7 | 9 ratings Rate this file 53 Downloads (last 30 days) File Size: 3.84 KB File ID: #34958 Version: 1.0
image thumbnail

JPEG Compression (DCT)



JPEG compression using Discrete Cosine Transform Technique

| Watch this File

File Information

In this code, Run Length Encoding is used to compress the Normalized DCT Coefficients, and corresponding Decoding techniques are used to decompress the image.

Required Products Image Acquisition Toolbox
Image Processing Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Other requirements The code is written to work on the images of size M X N where M and N are multiples of 8 (eg. 512 X 512). A little modification is required to accomodate the usage of images of other dimensions.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
11 Dec 2016 YEONHO CHOI

19 May 2016 Dat Tran

Thank you so much. It run very very good

Comment only
19 May 2016 Kenn Lu


Matlab code for jpeg compression using dct

Comment only
06 Sep 2015 Sonu Yadav

how to run and see the output

13 Aug 2014 fateh

fateh (view profile)

i got error at this line..
Error using dct1 (line 11)
Not enough input arguments.

Comment only
07 Jul 2014 hediye khosravi

dear Vinay,thanks for your usful code,but when i run it this error acure:
??? Error using ==> minus
Matrix dimensions must agree.

Error in ==> dct1 at 325

plz help me to run your code!

13 May 2014 Christin Panjaitan

I want to compress Depth Map 16-bit.
Is it possible ?

Comment only
21 Apr 2014 Mayuri

Mayuri (view profile)

I want the compressed image in matrix form. Is it possible?

Comment only
15 Nov 2013 Elysi Cochin

Sir this code works very well for gray images... I tried this for color images by converting the RGB to YCbCr and then did the code for each Y, Cb, Cr separately and then combined it.... it worked without any errors .... but the i couldnt restore the color image as the input image.... please could you help me to work with the color images also.... please do reply...

27 Jul 2013 Pooja

Pooja (view profile)

Hello, I am using a .raw format input image.I am getting error as too many output arguments.Could you please help me to solve the problem.Thank you..

Comment only
24 Feb 2013 Andrew

Andrew (view profile)

Thank you Vinay for the explanation. But for lower values of m,say 4, where bpp would then be 0.5, there appears a lot more block noise than expected at that bitrate. any adjustments you might suggest?

Comment only
23 Feb 2013 Vinay Kumar Tadepalli

Dear Andrew,

The n indicate the pixel depth of the input image. So, for an RGB Color image, it is 24, and for a monochrome image (gray scale image), it is 8 bits. And m indicates the amount of compression that you can afford. The range of m should be [1, n]. For example, when you are computing DCT for an 8-bit image, the DCT coefficients you obtain are normalized with normalization matrix and then rounded off (normalization+rounding off = quantization). And then these Quantized coefficients are converted to binary form and NOW you have a choice whether to retain all the bits of each DCT coefficient or only some. That will be specified by the user as m.

Note that both m and n are positive integers.

Hope it cleared your doubts.

Comment only
23 Feb 2013 Andrew

Andrew (view profile)

Hi Vinay, i run the DCT code but i need more explanation on the n,m part. e.g when i run n=8,m=2, i get an error about exceeding matrix dimensions. n is also indicated as bits per pixel, but when i try a value like n= 0.5, i still get an error.
Please enlighten me on that part(n,m) and how to use then to calculate the right bit per pixel values. Otherwise thank you for the code

12 Jan 2013 Vinay Kumar Tadepalli

Dear Mehdi, the code is not generalized for Images of arbitrary sizes. So, you have to include a code for padding additional rows and columns to make row number and column number a multiple of 2. That should solve the problem. If you have any other issues, let me know.

Comment only
11 Jan 2013 mehdi

mehdi (view profile)

thanks for Code, but when i run it i have this error Error using - Matrix dimensions must agree. Error in W (line 327) diff=im2double(I)*255-I_rec;

Comment only
08 Jan 2013 Vinay Kumar Tadepalli

Hi tonyk, M and N represent the non-overlapping block size in the entire image. That means, the digital image is divided into a number of blocks of dimension M X N. Typical values are M=N=8.

Comment only
08 Jan 2013 tonyk bui

plz tell me about m and n ?
i don't know

Comment only
12 Nov 2012 Ritesh Chandora

03 Oct 2012 RajiSantosh

Can this code be extended for three dimensional DCT?

02 May 2012 Vinay Kumar Tadepalli

One way is to encode the three color layers independently using the above method and then combine in the end. You may need to use some extra bits for separating b/w the binary data of each layer.

Comment only
26 Apr 2012 Fionn O'Donohoe

>>This code is written for GrayScale Image. >>But it can be easily modified to make it >>work for color images also.

How so?

Comment only
21 Mar 2012 Vinay Kumar Tadepalli

This code is written for GrayScale Image. But it can be easily modified to make it work for color images also.

Comment only
21 Mar 2012 shravan

does this work for colour image?

21 Mar 2012 chi

chi (view profile)


Comment only

Contact us