DCTune 2.0:

Perceptual Optimization of JPEG Images

(and Perceptual Error Metric)

Perceptual Error Map


DCTune is a technology for optimizing JPEG still image compression. DCTune calculates the best JPEG quantization matrices to achieve the maximum possible compression for a specified perceptual error, given a particular image and a particular set of viewing conditions. In DCTune, a target perceptual error of 1.0 means that for the specified viewing conditions the compressed JPEG image is perceptually lossless, that is, it will appear exactly the same as the original uncompressed image. DCTune is a patented technology available for licensing by NASA.

DCTune2.0 is a minimal implementation of DCTune technology that is offered free for demonstration purposes only. It takes a color image, computes the optimal quantization matrix, and generates both the matrix and the compressed image.

Image Quality Metric (NEW)

DCTune2.0 now allows the user to compute the perceptual error between two images. This perceptual error can be used to measure and control quality in many image coding, transmission, and processing applications. The demonstration above shows an original image, an image compressed by jpeg with visible artifacts, and an image showing the location and magnitude of visible errors in the jpeg image. If desired, DCTune2.0 can also generate a single number indicating the total perceptual error, or show how the errors are distributed over DCT frequency and color channel.

Why Use DCTune?

DCTune offers four key benefits:

  1. Accurate specification of visual quality. DCTune incorporates a scale that relates directly to perceptual quality. A value of 1 indicates perceptually lossless quality.
  2. Custom quantization matrices optimized for specific applications (printing, web, web-tv, medical imaging, tv, video, dv, digital tv, hdtv, etc).
  3. Reduced file size. For a given level of visual quality, DCTune will produce a smaller file than standard JPEG.
  4. Accurate measurement of perceptual error in processed images.

New in Version 2.0

  1. Computes perceptual error between two images. Thus DCTune2.0 can be used as a stand-alone image fidelity metric. To use this feature, use the -error option described below. See the domonstration in the images above.
  2. Allows user to specify tolerance in percent for bitrate or filesize optimization.

New in Version 1.2

  1. Fixes a bug which occurred with images containing a completely black macroblock.
  2. Prints a version number in the usage message.

New in Version 1.1

  1. User may now specify target file-size or bit-rate, instead of perceptual error.
  2. Viewing conditions may now be specified in dpi and viewing distance.
  3. In version 1.0, image width and height were required to be multiples of 16. This restriction has been removed.
  4. DCTune 1.1 reads a wider range of PPM and PGM files.


Executable versions of DCTune2.0 are available for download below. Each download consists of an executable, this documentation file, and a test image. After downloading, use the test image to verify that the program is working. These versions of DCTune are for evaluation and demonstration purposes only.


Version 2.0 of DCTune uses a command line argument interface on all platforms. On the MacOS, the arguments are entered into a text dialog box that appears when the application is launched. All arguments in square brackets are optional. Defaults are in curly braces.

 dctune  [-f <input file>]
   [ -p <target perceptual error> {1.0} ]
   [ -kbytes <target file size> ]
   [ -bpp <target bits per pixel> ]
   [ -sx <pixels per degree> {32} ]
   [ -sy <pixels per degree> {32} ]
   [ -inches <viewing distance> {25.33} ]
   [ -dpi <monitor dot pitch> {72} ]
   [ -o <quantization matrix file name> {qmatrix.txt} ]
   [ -j <output JPEG file name> {input-file.jpg}]
   [ -m ]
   [ -h ]
   [-error <reference file> <test file>]
   [-blocks] [<scale> {400}]
   [-tolerance <tolerance in percent> {5}]


-f <input-file>

The input file is an uncompressed 24-bit RGB or 8-bit grayscale image in Portable Pixmap (PPM/PBM/PGM) format. To convert files from other graphics formats to PPM:



Where to get it

 PC/Windows  WinJPEG   http://www.pixvision.com/
 Power Macintosh  GraphicConverter   http://www.lemkesoft.de/
 Unix/XWindows  xv   ftp://ftp.cis.upenn.edu/pub/xv

-p <target perceptual error> {1.0}

The target perceptual error is a real number greater than 0.0 A target perceptual error of 1.0 means that the compressed JPEG image will be perceptually identical (look the same) to the original uncompressed image under the specified viewing conditions.

-kbytes <target file size in Kilobytes>

Find the quantization matrices which produce a JPEG encoded image with the target file size in kilobytes and the best possible visual quality for that target file size. Overrides the -p and -bpp options.

-bpp <target bits per pixel>

Find the quantization matrices which produce a JPEG encoded image with the target bit-rate in bits/pixel and the best possible visual quality for that target bit-rate. Overrides the -p and -kbytes options.

-sx <pixels per degree> {32}

The number of pixels per degree of visual angle along the horizontal axis. This is determined by the display resolution and the viewing distance. Specifically, 57 * pixels/degree = viewing distance in pixels. For example, a 72 dpi monitor at 25.33 inches yields 32 pixels/degree.

-sy <pixels per degree> {32}

The number of pixels per degree of visual angle along the vertical axis. See notes for -sx.

-inches <viewing distance in inches> {25.33}

The distance from the viewer to the monitor screen in inches. Works with -dpi. Overrides the -sx and -sy options.

-dpi <monitor dot pitch in dots per inch> {72}

The monitor dot pitch in dots per inch.Works with -inches. Overrides the -inches and -sx and -sy options.

-o <quantization matrix file> {qmatrix.txt}

DCTune outputs the JPEG quantization matrices in an ASCII file in the format used by the Independent JPEG Group's JPEG encoder. The IJG JPEG encoder is also integrated into DCTune.

-j <output JPEG file name> {input-file.jpg}

Sets the name of the JPEG encoded image generated by DCTune. This defaults to the stem of the input file name with the jpg extension.


Turns off the DCTune JPEG perceptual optimization and uses the default quantization matrices in the Independent JPEG Group's JPEG encoder.


Help. Prints the version number, as well as a help message explaining options and usage of DCTune.

-error <reference file> <test file>

Computes the perceptual error, in units of jnd (just-noticeable differences) between a reference image and a test image. Unless the -blocks or -matrices options are selected, this returns a single number. Both images must be in the format described under the -f argument. -error overrides -f.

-blocks <scale>

In conjunction with the -error option, returns the error as an 8-bit grayscale PPM image blocks.ppm, depicting the pooled jnds within each macroblock (the error is pooled only over color (Y, Cb, and Cr) and DCT frequency). The scale factor determines the mapping from jnd to grayscale; the default is 400 (eg 0.5 jnd ->200 grayscale).


In conjunction with the -error option, returns the error as three 8x8 matrices, depicting the pooled jnds within each color (Y, Cb, and Cr) and DCT frequency (the error is pooled only over macroblocks). The matrices are written out to a file called matrices.txt.


In conjunction with the -bpp or -kbytes options, specifies the accuracy with which bitrate or filesize goal must be met. The default is 5%.

Notes on the Demo

The images at the top of this page illustrate the perceptual error metric capability of DCTune2.0. An original image 04s.ppm was first compressed using DCTune2.0 and the command line:

-f 04s.ppm

This creates a JPEG file called 04s.jpg. This file was then converted back to ppm format (04s.d.ppm) using the shareware program GraphicConverter. The perceptual error in each macroblock was then computed by DCTune2.0 using the command line:

-error 04s.ppm 04s.d.ppm -blocks

This creates a new image (blocks.pgm) which we then magnified by 16 in width and height using GraphicConverter to produce blocks.ppm. 04s.ppm and blocks.ppm were then converted (using GraphicConverter) to JPEG files 04s.jpg and blocks.jpg using the highest quality setting. These last files were created only for rapid internet access of the web page.

The image blocks.ppm depicts the perceptual error, in jnds x 400, in each macroblock of the compressed image 04s.d.jpg.

Technical Notes


The DCTune algorithm is covered by a United States patent (U.S. Patent 5,426,512). For information on licensing DCTune consult the DCTune Technology Licensing Web Page noted below.


The DCTune algorithm was developed by Dr. Andrew B. Watson, Dr. Albert Ahumada, and others with the Vision Science and Technology Group at NASA Ames Research Center. DCTune was developed as a Mathematica prototype by Andrew B. Watson. John F. McGowan, Ph.D. of the Desktop Video Expert Center at NASA Ames Research Center and Mark A. Young, Ph.D. of the Vision Group converted DCTune to the C language.

DCTune 2.0 incorporates version 6a of the Independent JPEG Group's JPEG Encoder.

Links to DCTune-related resources

 DCTune Patent  http://vision.arc.nasa.gov/publications/patent97.pdf
 DCTune Publications  http://vision.arc.nasa.gov/publications/publications.html#ImageCompression
 DCTune Technology Licensing
 Vision Group  http://vision.arc.nasa.gov/

Contact Information

Andrew B. Watson
MS 262-2
NASA Ames Research Center
Moffett Field, CA 94035-1000