Steve on Image Processing

Concepts, algorithms & MATLAB

Discrete cosine transforms, JPEG, and software compatibility 9

Posted by Steve Eddins,

Software compatibility is a tricky subject. No one likes it when an incompatible change occurs in a software application they rely on. So why do we sometimes find it necessary to make an incompatible change? Here's an illustrative story from the early days of the Image Processing Toolbox.

The function dct2, which computes the two-dimensional discrete cosine transform (DCT), appeared in the original 1993 version of the toolbox. The authors of the toolbox relied on several authoritative references, including Two-Dimensional Signal and Image Processing by Lim. This book contains the following one-dimensional DCT equation:

The original implementation of dct2 used this formula.

At roughly the same time as the first toolbox release, the newly-standardized JPEG image compression method and format was becoming popular. The DCT is the mathematical heart of the JPEG algorithm. Here's the 8-point one-dimensional DCT equation that appears in JPEG: Still Image Data Compression Standard by Pennebaker and Mitchell.


The variable name differences are trivial, but the scale factor differences are very important! The JPEG DCT is an orthonormal transform, whereas the DCT defined in Lim's book is not.

Users of version 1 began to contact tech support, wondering why dct2 was giving the "wrong" answer. We realized that we would have to do something, but what? Changing the output of dct2 would introduce an incompatibility. Not changing it would let user confusion and tech support calls continue indefinitely.

We eventually made a decision based on the fact that image compression is the only widespread application of the DCT in image processing. Therefore, it made no sense for our function to produce an answer inconsistent with the standardized DCT-based image compression method. So we changed the output of dct2 in version 2 of the toolbox. When no complaints came in about the change, we breathed a sigh of relief.

Today at The MathWorks we have processes in place to carefully evaluate changes that might result in an incompatibility. What options have the developers considered? What steps are being taken to mitigate possible negative impacts of the change? What is the benefit to the user of the change?

Whether we are doing a good job or not is up to you to judge. How do you think we are doing? How has the evolution of MATLAB over the years affected your work? Have any good stories to tell? Leave your comments here.

Get the MATLAB code

Published with MATLAB® 7.2


Comments are closed.

9 CommentsOldest to Newest

Nita replied on : 1 of 9

Hello Steve,

How I connect digital camera with Matlab 6.5 ? I am using Image aquation toolbox 1.0.
Can it possible with Matlab 6.5 or any other external device required ?

Kindly help me.


dipti venkatesan replied on : 3 of 9

hi steve,
we are doin a project on image processing which involves image compression of biomedical image.. so i request you to help me out with the matlab code for lzw method for compressing an image… thank u..

Hari Kiran replied on : 4 of 9

Hi Steve,
Thanks a lot for the support you r providing. I am working on steganography using Genetic algorithms on JPEG images. I am stuck at a point where I have to compute DCT over a JPEG image. The MATLAB image processing toolbox provides a function dct2 which can compute dct coefficients for a two dimensional image like GIF or bmp…but JPEG images when read thru imread in MATLAB come out as three dimensional how to compute dct on this 3 dimensional matrix..Kindly help me out..

Steve replied on : 5 of 9

Hari—JPEG and similar compression algorithms apply the DCT on a block-by-block basis to individual color components, not to all three components at a time. Also, JPEG algorithms usually compress color images by converting RGB images to a different color space and downsampling the new color components. You might need to obtain some reference material on JPEG if you are serious about implement such algorithms.

Eman replied on : 6 of 9

Hi Steve ,
I am working on an JPEG authentication project. I use the VB.Net but I found it doesn’t good enough for image manipulating.
I realy need to play with the quantized DCT matrix values.
the question is do you advice me to use MATLAB for this project.

I need your advice.
for more information I will be happy to recive an email from you

in advance, thanks alot

Steve replied on : 7 of 9

Eman—In my completely biased opinion, I think that MATLAB (with the Image Processing Toolbox) is a terrific tool for your project.

anmol replied on : 8 of 9

i am currently working on a project on image processing, i wanted to extract features of DCTb (80 * 64).I did come up with something but was not sure whether its correct or not what kind of output would we be expecting???

Steve replied on : 9 of 9

Anmol—I don’t know what your project is. I don’t know what a DCTb is or what kind of features you want from it. I don’t know what you came up with (other than it was something) or what the result was.

You might try being a little more specific. :-)