{{Other uses}}
In
computingComputing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...
,
JPEG (icon [pronounced as jay - peg] is a commonly used method of lossy compression for
digital photographyDigital photography is a form of photography that uses an array of light sensitive sensors to capture the image focused by the lens, as opposed to an exposure on light sensitive film...
(image). The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality.
JPEG compression is used in a number of
image file formatsImage file formats are standardized means of organizing and storing digital images. Image files are composed of either pixels, vector data, or a combination of the two. Whatever the format, the files are rasterized to pixels when displayed on most graphic displays...
. JPEG/Exif is the most common image format used by digital cameras and other photographic image capture devices; along with JPEG/JFIF, it is the most common format for storing and transmitting photographic images on the
World Wide WebThe World Wide Web is a system of interlinked hypertext documents accessed via the Internet...
.{{Citation needed|date=February 2010}} These format variations are often not distinguished, and are simply called JPEG.
The term "JPEG" is an acronym for the
Joint Photographic Experts GroupThe Joint Photographic Experts Group is the joint committee between ISO/IEC JTC1 and ITU-T that created the JPEG, JPEG 2000, and JPEG XR standards. It is one of two sub-groups of ISO/IEC Joint Technical Committee 1, Subcommittee 29, Working Group 1 - titled as Coding of still pictures...
which created the standard. The
MIME media typeAn Internet media type, originally called a MIME type after MIME and sometimes a Content-type after the name of a header in several protocols whose value is such a type, is a two-part identifier for file formats on the Internet.The identifiers were originally defined in RFC 2046 for use in email...
for JPEG is
image/jpeg (defined in RFC 1341), except in
Internet ExplorerWindows Internet Explorer is a series of graphical web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year...
, which provides a MIME type of
image/pjpeg when uploading JPEG images.
It supports a maximum image size of 65535×65535.
The JPEG standard
The name "JPEG" stands for
Joint Photographic Experts GroupThe Joint Photographic Experts Group is the joint committee between ISO/IEC JTC1 and ITU-T that created the JPEG, JPEG 2000, and JPEG XR standards. It is one of two sub-groups of ISO/IEC Joint Technical Committee 1, Subcommittee 29, Working Group 1 - titled as Coding of still pictures...
, the name of the committee that created the JPEG standard and also other standards. It is one of two sub-groups of
ISOThe International Organization for Standardization , widely known as ISO, is an international standard-setting body composed of representatives from various national standards organizations. Founded on February 23, 1947, the organization promulgates worldwide proprietary, industrial and commercial...
/
IECThe International Electrotechnical Commission is a non-profit, non-governmental international standards organization that prepares and publishes International Standards for all electrical, electronic and related technologies – collectively known as "electrotechnology"...
Joint Technical Committee 1, Subcommittee 29, Working Group 1 (ISO/IEC JTC 1/SC 29/WG 1) – titled as
Coding of still pictures. The group was organized in 1986, issuing the first JPEG standard in 1992, which was approved in September 1992 as
ITU-TThe ITU Telecommunication Standardization Sector is one of the three sectors of the International Telecommunication Union ; it coordinates standards for telecommunications....
Recommendation T.81 and in 1994 as
ISOThe International Organization for Standardization , widely known as ISO, is an international standard-setting body composed of representatives from various national standards organizations. Founded on February 23, 1947, the organization promulgates worldwide proprietary, industrial and commercial...
/IECThe International Electrotechnical Commission is a non-profit, non-governmental international standards organization that prepares and publishes International Standards for all electrical, electronic and related technologies – collectively known as "electrotechnology"...
10918-1.
The JPEG standard specifies the
codecA codec is a device or computer program capable of encoding or decoding a digital data stream or signal. The word codec is a portmanteau of "compressor-decompressor" or, more commonly, "coder-decoder"...
, which defines how an image is compressed into a stream of
byteThe byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...
s and decompressed back into an image, but not the file format used to contain that stream.
The Exif and JFIF standards define the commonly used file formats for interchange of JPEG-compressed images.
JPEG standards are formally named as
Information technology—Digital compression and coding of continuous-tone still images. ISO/IEC 10918 consists of the following parts:
NEWLINE
NEWLINEJPEG standard – PartsNEWLINENEWLINE| Part | NEWLINEISO/IEC standard | NEWLINEITU-T Rec. | NEWLINEFirst public release date | NEWLINELatest amendment | NEWLINETitle | NEWLINE Description | NEWLINE
NEWLINE| Part 1 | NEWLINE ISO/IEC 10918-1:1994 | NEWLINE T.81 (09/92) | NEWLINE 1992 | NEWLINE | NEWLINE Requirements and guidelines | NEWLINE | NEWLINE
NEWLINE| Part 2 | NEWLINE ISO/IEC 10918-2:1995 | NEWLINE T.83 (11/94) | NEWLINE 1994 | NEWLINE | NEWLINE Compliance testing | NEWLINE rules and checks for software conformance (to Part 1) | NEWLINE
NEWLINE| Part 3 | NEWLINE ISO/IEC 10918-3:1997 | NEWLINE T.84 (07/96) | NEWLINE 1996 | NEWLINE 1999 | NEWLINE Extensions | NEWLINE set of extensions to improve the Part 1, including the SPIFF file format | NEWLINE
NEWLINE| Part 4 | NEWLINE ISO/IEC 10918-4:1999 | NEWLINE T.86 (06/98) | NEWLINE 1998 | NEWLINE | NEWLINE Registration of JPEG profiles, SPIFF profiles, SPIFF tags, SPIFF colour spaces, APPn markers, SPIFF compression types and Registration Authorities (REGAUT) | NEWLINE methods for registering some of the parameters used to extend JPEG | NEWLINE
NEWLINE| Part 5 | NEWLINE ISO/IEC FDIS 10918-5 | NEWLINE | NEWLINE (under development since 2009) | NEWLINE | NEWLINE JPEG File Interchange Format (JFIF) | NEWLINE A popular format which has been the de-facto file format for images encoded by the JPEG standard. In 2009, the JPEG Committee formally established an Ad Hoc Group to standardize JFIF as JPEG Part 5. | NEWLINE
NEWLINENEWLINE
Ecma InternationalEcma International is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's global reach and activities...
TR/98 specifies the JPEG File Interchange Format (JFIF); the first edition was published in June 2009.
Typical usage
The JPEG compression algorithm is at its best on photographs and paintings of realistic scenes with smooth variations of tone and color. For web usage, where the amount of data used for an image is important, JPEG is very popular. JPEG/Exif is also the most common format saved by digital cameras.
On the other hand, JPEG may not be as well suited for line drawings and other textual or iconic graphics, where the sharp contrasts between adjacent pixels can cause noticeable artifacts. Such images may be better saved in a lossless graphics format such as TIFF, GIF, PNG, or a
raw image formatA camera raw image file contains minimally processed data from the image sensor of either a digital camera, image scanner, or motion picture film scanner. Raw files are so named because they are not yet processed and therefore are not ready to be printed or edited with a bitmap graphics editor...
. The JPEG standard actually includes a lossless coding mode, but that mode is not supported in most products.
As the typical use of JPEG is a lossy compression method, which somewhat reduces the image fidelity, it should not be used in scenarios where the exact reproduction of the data is required (such as some scientific and medical imaging applications and certain technical
image processingIn electrical engineering and computer science, image processing is any form of signal processing for which the input is an image, such as a photograph or video frame; the output of image processing may be either an image or, a set of characteristics or parameters related to the image...
work).
JPEG is also not well suited to files that will undergo multiple edits, as some image quality will usually be lost each time the image is decompressed and recompressed, particularly if the image is cropped or shifted, or if encoding parameters are changed – see digital generation loss for details. To avoid this, an image that is being modified or may be modified in the future can be saved in a lossless format, with a copy exported as JPEG for distribution.
JPEG compression
The compression method is usually lossy, meaning that some original image information is lost and cannot be restored, possibly affecting image quality. There is an optional lossless mode defined in the JPEG standard; however, that mode is not widely supported in products.
There is also an
interlaceInterlacing is a method of encoding a bitmap image such that a person who has partially received it sees a degraded copy of the entire image. When communicating over a slow communications link, this is often preferable to seeing a perfectly clear copy of one part of the image, as it helps the...
d "Progressive JPEG" format, in which data is compressed in multiple passes of progressively higher detail. This is ideal for large images that will be displayed while downloading over a slow connection, allowing a reasonable preview after receiving only a portion of the data. However, progressive JPEGs are not as widely supported {{citation needed|date=October 2011}}, and even some software which does support them (such as some versions of Internet Explorer) only displays the image once it has been completely downloaded.
There are also many medical imaging and traffic systems that create and process 12-bit JPEG images, normally grayscale images. The 12-bit JPEG format has been part of the JPEG specification for some time, but again, this format is not as widely supported.
Lossless editing
{{See also|jpegtran}}
A number of alterations to a JPEG image can be performed losslessly (that is, without recompression and the associated quality loss) as long as the image size is a multiple of 1 MCU block (Minimum Coded Unit) (usually 16 pixels in both directions, for 4:2:0
chroma subsamplingChroma subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information, taking advantage of the human visual system's lower acuity for color differences than for luminance....
). Utilities that implement this include
jpegtran, with user interface Jpegcrop, and the
JPG_TRANSFORM plugin to
IrfanViewIrfanView is a freeware/shareware image viewer for Microsoft Windows that can view, edit, and convert image files and play video/audio files. It is noted for its small size, speed, ease of use, and ability to handle a wide variety of graphic file formats, and has some image creation and painting...
.
Blocks can be rotated in 90 degree increments, flipped in the horizontal, vertical and diagonal axes and moved about in the image. Not all blocks from the original image need to be used in the modified one.
The top and left edge of a JPEG image must lie on a block boundary, but the bottom and right edge need not do so. This limits the possible lossless crop operations, and also prevents flips and rotations of an image whose bottom or right edge does not lie on a block boundary for all channels (because the edge would end up on top or left, where - as aforementioned - a block boundary is obligatory).
When using lossless cropping, if the bottom or right side of the crop region is not on a block boundary then the rest of the data from the partially used blocks will still be present in the cropped file and can be recovered.
It is also possible to transform between baseline and progressive formats without any loss of quality, since the only difference is the order in which the coefficients are placed in the file.
JPEG files
The
file formatA file format is a particular way that information is encoded for storage in a computer file.Since a disk drive, or indeed any computer storage, can store only bits, the computer must have some way of converting information to 0s and 1s and vice-versa. There are different kinds of formats for...
known as "JPEG Interchange Format" (JIF) is specified in Annex B of the standard. However, this "pure" file format is rarely used, primarily because of the difficulty of programming encoders and decoders that fully implement all aspects of the standard and because of certain shortcomings of the standard:
NEWLINE
NEWLINE- Color space definition
NEWLINE- Component sub-sampling registration
NEWLINE- Pixel aspect ratio definition.
NEWLINE
Several additional standards have evolved to address these issues. The first of these, released in 1992, was
JPEG File Interchange FormatThe JPEG File Interchange Format is an image file format standard. It is a format for exchanging JPEG encoded files compliant with the JPEG Interchange Format standard. It solves some of JIFs limitations in regard to simple JPEG encoded file interchange...
(or JFIF), followed in recent years by
Exchangeable image file formatExchangeable image file format is a standard that specifies the formats for images, sound, and ancillary tags used by digital cameras , scanners and other systems handling image and sound files recorded by digital cameras...
(Exif) and
ICCThe International Color Consortium was formed in 1993 by eight industry vendors in order to create a universal color management system that would function transparently across all operating systems and software packages....
color profilesIn color management, an ICC profile is a set of data that characterizes a color input or output device, or a color space, according to standards promulgated by the International Color Consortium...
. Both of these formats use the actual JIF byte layout, consisting of different
markers, but in addition employ one of the JIF standard's extension points, namely the
application markers: JFIF use APP0, while Exif use APP1. Within these segments of the file, that were left for future use in the JIF standard and aren't read by it, these standards add specific metadata.
Thus, in some ways JFIF is a cutdown version of the JIF standard in that it specifies certain constraints (such as not allowing all the different encoding modes), while in other ways it is an extension of JIF due to the added metadata. The documentation for the original JFIF standard states:
NEWLINE
NEWLINE- JPEG File Interchange Format is a minimal file format which enables JPEG bitstreams to be exchanged between a wide variety of platforms and applications. This minimal format does not include any of the advanced features found in the TIFF JPEG specification or any application specific file format. Nor should it, for the only purpose of this simplified format is to allow the exchange of JPEG compressed images.
NEWLINE
Image files that employ JPEG compression are commonly called "JPEG files", and are stored in variants of the JIF image format. Most image capture devices (such as digital cameras) that output JPEG are actually creating files in the Exif format, the format that the camera industry has standardized on for metadata interchange. On the other hand, since the Exif standard does not allow color profiles, most image editing software stores JPEG in JFIF format, and also include the APP1 segment from the Exif file to include the metadata in an almost-compliant way; the JFIF standard is interpreted somewhat flexibly.
Strictly speaking, the JFIF and Exif standards are incompatible because they each specify that their marker segment (APP0 or APP1, respectively) appears first. In practice, most JPEG files contain a JFIF marker segment that precedes the Exif header. This allows older readers to correctly handle the older format JFIF segment, while newer readers also decode the following Exif segment, being less strict about requiring it to appear first.
JPEG filename extensions
The most common
filename extensionA filename extension is a suffix to the name of a computer file applied to indicate the encoding of its contents or usage....
s for files employing JPEG compression are
.jpg and
.jpeg, though .jpe, .jfif and .jif are also used. It is also possible for JPEG data to be embedded in other file types –
TIFFTIFF is a file format for storing images, popular among graphic artists, the publishing industry, and both amateur and professional photographers in general. As of 2009, it is under the control of Adobe Systems...
encoded files often embed a JPEG image as a
thumbnailThumbnails are reduced-size versions of pictures, used to help in recognizing and organizing them, serving the same role for images as a normal text index does for words...
of the main image; and
MP3MPEG-1 or MPEG-2 Audio Layer III, more commonly referred to as MP3, is a patented digital audio encoding format using a form of lossy data compression...
files can contain a JPEG of
cover artCover art is the illustration or photograph on the outside of a published product such as a book , magazine, comic book, video game , DVD, CD, videotape, or music album. The art has a primarily commercial function, i.e...
, in the ID3v2 tag.
Color profile
Many JPEG files embed an
ICC color profileIn color management, an ICC profile is a set of data that characterizes a color input or output device, or a color space, according to standards promulgated by the International Color Consortium...
(
color spaceA color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components...
). Commonly used color profiles include
sRGBsRGB is a standard RGB color space created cooperatively by HP and Microsoft in 1996 for use on monitors, printers, and the Internet.sRGB uses the ITU-R BT.709 primaries, the same as are used in studio monitors and HDTV, and a transfer function typical of CRTs...
and
Adobe RGBThe Adobe RGB color space is an RGB color space developed by Adobe Systems in 1998. It was designed to encompass most of the colors achievable on CMYK color printers, but by using RGB primary colors on a device such as the computer display...
. Because these color spaces use a non-linear transformation, the
dynamic rangeDynamic range, abbreviated DR or DNR, is the ratio between the largest and smallest possible values of a changeable quantity, such as in sound and light. It is measured as a ratio, or as a base-10 or base-2 logarithmic value.-Dynamic range and human perception:The human senses of sight and...
of an 8-bit JPEG file is about 11
stopsIn optics, the f-number of an optical system expresses the diameter of the entrance pupil in terms of the focal length of the lens; in simpler terms, the f-number is the focal length divided by the "effective" aperture diameter...
; see gamma curve. However, many applications are not able to deal with JPEG color profiles and simply ignore them.
Syntax and structure
A JPEG image consists of a sequence of
segments, each beginning with a
marker, each of which begins with a 0xFF byte followed by a byte indicating what kind of marker it is. Some markers consist of just those two bytes; others are followed by two bytes indicating the length of marker-specific payload data that follows. (The length includes the two bytes for the length, but not the two bytes for the marker.) Some markers are followed by entropy-coded data; the length of such a marker does not include the entropy-coded data. Note that consecutive 0xFF bytes are used as fill bytes for padding purposes (see JPEG specification section B.1.1.2 for details).
Within the entropy-coded data, after any 0xFF byte, a 0x00 byte is inserted by the encoder before the next byte, so that there does not appear to be a marker where none is intended, preventing framing errors. Decoders must skip this 0x00 byte. This technique, called
byte stuffing (see JPEG specification section F.1.2.3), is only applied to the entropy-coded data, not to marker payload data.
NEWLINE
NEWLINE Common JPEG markersNEWLINE| Short name | NEWLINE Bytes | NEWLINE Payload | NEWLINE Name | NEWLINE Comments | NEWLINENEWLINE| SOI | NEWLINE 0xFF, 0xD8 | NEWLINE none | NEWLINE Start Of Image | NEWLINE | NEWLINE
NEWLINE| SOF0 | NEWLINE 0xFF, 0xC0 | NEWLINE variable size | NEWLINE Start Of Frame (Baseline DCT A discrete cosine transform expresses a sequence of finitely many data points in terms of a sum of cosine functions oscillating at different frequencies. DCTs are important to numerous applications in science and engineering, from lossy compression of audio and images A discrete cosine transform... ) | NEWLINE Indicates that this is a baseline DCT-based JPEG, and specifies the width, height, number of components, and component subsampling (e.g., 4:2:0). | NEWLINE
NEWLINE| SOF2 | NEWLINE 0xFF, 0xC2 | NEWLINE variable size | NEWLINE Start Of Frame (Progressive DCT) | NEWLINE Indicates that this is a progressive DCT-based JPEG, and specifies the width, height, number of components, and component subsampling (e.g., 4:2:0). | NEWLINE
NEWLINE| DHT | NEWLINE 0xFF, 0xC4 | NEWLINE variable size | NEWLINE Define Huffman Table(s) | NEWLINE Specifies one or more Huffman tables. | NEWLINE
NEWLINE| DQT | NEWLINE 0xFF, 0xDB | NEWLINE variable size | NEWLINE Define Quantization Table(s) | NEWLINE Specifies one or more quantization tables. | NEWLINE
NEWLINE| DRI | NEWLINE 0xFF, 0xDD | NEWLINE 2 bytes | NEWLINE Define Restart Interval | NEWLINE Specifies the interval between RSTn markers, in macroblocks. This marker is followed by two bytes indicating the fixed size so it can be treated like any other variable size segment. | NEWLINE
NEWLINE| SOS | NEWLINE 0xFF, 0xDA | NEWLINE variable size | NEWLINE Start Of Scan | NEWLINE Begins a top-to-bottom scan of the image. In baseline DCT JPEG images, there is generally a single scan. Progressive DCT JPEG images usually contain multiple scans. This marker specifies which slice of data it will contain, and is immediately followed by entropy-coded data. | NEWLINE
NEWLINE| RSTn | NEWLINE 0xFF, 0xD0 … 0xD7 | NEWLINE none | NEWLINE Restart | NEWLINE Inserted every r macroblocks, where r is the restart interval set by a DRI marker. Not used if there was no DRI marker. The low 3 bits of the marker code cycle in value from 0 to 7. | NEWLINE
NEWLINE| APPn | NEWLINE 0xFF, 0xEn | NEWLINE variable size | NEWLINE Application-specific | NEWLINE For example, an Exif JPEG file uses an APP1 marker to store metadata, laid out in a structure based closely on TIFF. | NEWLINE
NEWLINE| COM | NEWLINE 0xFF, 0xFE | NEWLINE variable size | NEWLINE Comment | NEWLINE Contains a text comment. | NEWLINE
NEWLINE| EOI | NEWLINE 0xFF, 0xD9 | NEWLINE none | NEWLINE End Of Image | NEWLINE | NEWLINE
NEWLINENEWLINE
There are other
Start Of Frame markers that introduce other kinds of JPEG encodings.
Since several vendors might use the same APP
n marker type, application-specific markers often begin with a standard or vendor name (e.g., "Exif" or "Adobe") or some other identifying string.
At a restart marker, block-to-block predictor variables are reset, and the bitstream is synchronized to a byte boundary. Restart markers provide means for recovery after bitstream error, such as transmission over an unreliable network or file corruption. Since the runs of macroblocks between restart markers may be independently decoded, these runs may be decoded in parallel.
JPEG codec example
Although a JPEG file can be encoded in various ways, most commonly it is done with JFIF encoding. The encoding process consists of several steps:NEWLINE
NEWLINE- The representation of the colors in the image is converted from RGB
The RGB color model is an additive color model in which red, green, and blue light is added together in various ways to reproduce a broad array of colors...
to {{YCbCr}}YCbCr or Y′CbCr, sometimes written or , is a family of color spaces used as a part of the color image pipeline in video and digital photography systems. Y′ is the luma component and CB and CR are the blue-difference and red-difference chroma components...
, consisting of one lumaIn video, luma, sometimes called luminance, represents the brightness in an image . Luma is typically paired with chrominance. Luma represents the achromatic image without any color, while the chroma components represent the color information...
component (Y'), representing brightness, and two chromaChrominance is the signal used in video systems to convey the color information of the picture, separately from the accompanying luma signal . Chrominance is usually represented as two color-difference components: U = B' − Y' and V = R' − Y'...
components, (CB and CR), representing color. This step is sometimes skipped. NEWLINE- The resolution of the chroma data is reduced, usually by a factor of 2. This reflects the fact that the eye is less sensitive to fine color details than to fine brightness details.
NEWLINE- The image is split into blocks of 8×8 pixels, and for each block, each of the Y, CB, and CR data undergoes a discrete cosine transform
A discrete cosine transform expresses a sequence of finitely many data points in terms of a sum of cosine functions oscillating at different frequencies. DCTs are important to numerous applications in science and engineering, from lossy compression of audio and images A discrete cosine transform...
(DCT). A DCT is similar to a Fourier transformIn mathematics, Fourier analysis is a subject area which grew from the study of Fourier series. The subject began with the study of the way general functions may be represented by sums of simpler trigonometric functions...
in the sense that it produces a kind of spatial frequency spectrum. NEWLINE- The amplitudes of the frequency components are quantized
Quantization, involved in image processing, is a lossy compression technique achieved by compressing a range of values to a single quantum value. When the number of discrete symbols in a given stream is reduced, the stream becomes more compressible. For example, reducing the number of colors...
. Human vision is much more sensitive to small variations in color or brightness over large areas than to the strength of high-frequency brightness variations. Therefore, the magnitudes of the high-frequency components are stored with a lower accuracy than the low-frequency components. The quality setting of the encoder (for example 50 or 95 on a scale of 0–100 in the Independent JPEG Group's library) affects to what extent the resolution of each frequency component is reduced. If an excessively low quality setting is used, the high-frequency components are discarded altogether. NEWLINE- The resulting data for all 8×8 blocks is further compressed with a lossless algorithm, a variant of Huffman encoding.
NEWLINE
The decoding process reverses these steps, except the
quantization because it is irreversible. In the remainder of this section, the encoding and decoding processes are described in more detail.
Encoding
Many of the options in the JPEG standard are not commonly used, and as mentioned above, most image software uses the simpler JFIF format when creating a JPEG file, which among other things specifies the encoding method. Here is a brief description of one of the more common methods of encoding when applied to an input that has 24 bits per pixel (eight each of
red, green, and blueThe RGB color model is an additive color model in which red, green, and blue light is added together in various ways to reproduce a broad array of colors...
). This particular option is a
lossy data compressionIn information technology, "lossy" compression is a data encoding method that compresses data by discarding some of it. The procedure aims to minimize the amount of data that need to be held, handled, and/or transmitted by a computer...
method. {{Citation needed|date=May 2011}}
Color space transformation
First, the image should be converted from
RGBThe RGB color model is an additive color model in which red, green, and blue light is added together in various ways to reproduce a broad array of colors...
into a different
color spaceA color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components...
called
{{YCbCr}}YCbCr or Y′CbCr, sometimes written or , is a family of color spaces used as a part of the color image pipeline in video and digital photography systems. Y′ is the luma component and CB and CR are the blue-difference and red-difference chroma components...
(or, informally, YCbCr). It has three components Y', C
B and C
R: the Y' component represents the brightness of a pixel, and the C
B and C
R components represent the
chrominanceChrominance is the signal used in video systems to convey the color information of the picture, separately from the accompanying luma signal . Chrominance is usually represented as two color-difference components: U = B' − Y' and V = R' − Y'...
(split into blue and red components). This is basically the same color space as used by
digital color televisionDigital television is the transmission of audio and video by digital signals, in contrast to the analog signals used by analog TV...
as well as digital video including video DVDs, and is similar to the way color is represented in analog
PALPAL, short for Phase Alternating Line, is an analogue television colour encoding system used in broadcast television systems in many countries. Other common analogue television systems are NTSC and SECAM. This page primarily discusses the PAL colour encoding system...
video and
MACMultiplexed Analogue Components was a satellite television transmission standard, originally proposed for use on a Europe-wide terrestrial HDTV system, although it was never used terrestrially.- Technical overview :...
(but not by analog
NTSCNTSC, named for the National Television System Committee, is the analog television system that is used in most of North America, most of South America , Burma, South Korea, Taiwan, Japan, the Philippines, and some Pacific island nations and territories .Most countries using the NTSC standard, as...
, which uses the
YIQYIQ is the color space used by the NTSC color TV system, employed mainly in North and Central America, and Japan. It is currently in use only for low-power television stations, as full-power analog transmission was ended by the U.S. Federal Communications Commission on 12 June 2009...
color space). The {{YCbCr}} color space conversion allows greater compression without a significant effect on perceptual image quality (or greater perceptual image quality for the same compression). The compression is more efficient because the brightness information, which is more important to the eventual perceptual quality of the image, is confined to a single channel. This more closely corresponds to the perception of color in the human visual system. The color transformation also improves compression by statistical
decorrelationDecorrelation is a general term for any process that is used to reduce autocorrelation within a signal, or cross-correlation within a set of signals, while preserving other aspects of the signal. A frequently used method of decorrelation is the use of a matched linear filter to reduce the...
.
A particular conversion to {{YCbCr}} is specified in the JFIF standard, and should be performed for the resulting JPEG file to have maximum compatibility. However, some JPEG implementations in "highest quality" mode do not apply this step and instead keep the color information in the
RGB color modelThe RGB color model is an additive color model in which red, green, and blue light is added together in various ways to reproduce a broad array of colors...
{{Citation needed|date=February 2008}}, where the image is stored in separate channels for red, green and blue brightness components. This results in less efficient compression, and would not likely be used when file size is especially important.
Downsampling
Due to the densities of color- and brightness-sensitive receptors in the human eye, humans can see considerably more fine detail in the brightness of an image (the Y' component) than in the hue and color saturation of an image (the Cb and Cr components). Using this knowledge, encoders can be designed to compress images more efficiently.
The transformation into the
{{YCbCr}} color modelYCbCr or Y′CbCr, sometimes written or , is a family of color spaces used as a part of the color image pipeline in video and digital photography systems. Y′ is the luma component and CB and CR are the blue-difference and red-difference chroma components...
enables the next usual step, which is to reduce the spatial resolution of the Cb and Cr components (called "
downsamplingIn signal processing, downsampling is the process of reducing the sampling rate of a signal. This is usually done to reduce the data rate or the size of the data....
" or "
chroma subsamplingChroma subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information, taking advantage of the human visual system's lower acuity for color differences than for luminance....
"). The ratios at which the downsampling is ordinarily done for JPEG images are 4:4:4 (no downsampling), 4:2:2 (reduction by a factor of 2 in the horizontal direction), or (most commonly) 4:2:0 (reduction by a factor of 2 in both the horizontal and vertical directions). For the rest of the compression process, Y', Cb and Cr are processed separately and in a very similar manner.
Block splitting
After
subsamplingChroma subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information, taking advantage of the human visual system's lower acuity for color differences than for luminance....
, each
channelColor digital images are made of pixels, and pixels are made of combinations of primary colors. A channel in this context is the grayscale image of the same size as a color image, made of just one of these primary colors. For instance, an image from a standard digital camera will have a red, green...
must be split into 8×8 blocks. Depending on chroma subsampling, this yields (Minimum Coded Unit) MCU blocks of size 8×8 (4:4:4 – no subsampling), 16×8 (4:2:2), or most commonly 16×16 (4:2:0). In video compression MCUs are called
macroblock Macroblock is an image compression component and technique based on discrete cosine transform used on still images and video frames. Macroblocks are usually composed of two or more blocks of pixels. In the JPEG standard macroblocks are called MCU blocks....
s.
If the data for a channel does not represent an integer number of blocks then the encoder must fill the remaining area of the incomplete blocks with some form of dummy data. Filling the edges with a fixed color (for example, black) can create ringing artifacts along the visible part of the border;
repeating the edge pixels is a common technique that reduces (but does not necessarily completely eliminate) such artifacts, and more sophisticated border filling techniques can also be applied.
Discrete cosine transform
Next, each 8×8 block of each component (Y, Cb, Cr) is converted to a frequency-domain representation, using a normalized, two-dimensional type-II
discrete cosine transformA discrete cosine transform expresses a sequence of finitely many data points in terms of a sum of cosine functions oscillating at different frequencies. DCTs are important to numerous applications in science and engineering, from lossy compression of audio and images A discrete cosine transform...
(DCT).
As an example, one such 8×8 8-bit subimage might be:
Before computing the DCT of the 8×8 block, its values are shifted from a positive range to one centered around zero. For an 8-bit image, each entry in the original block falls in the range
. The mid-point of the range (in this case, the value 128) is subtracted from each entry to produce a data range that is centered around zero, so that the modified range is
. This step reduces the dynamic range requirements in the DCT processing stage that follows. (Aside from the difference in dynamic range within the DCT stage, this step is mathematically equivalent to subtracting 1024 from the
DC coefficientWhen describing a periodic function in the frequency domain, the DC bias, DC component, DC offset, or DC coefficient is the mean value of the waveform...
after performing the transform – which may be a better way to perform the operation on some architectures since it involves performing only one subtraction rather than 64 of them.)
This step results in the following values:
The next step is to take the two-dimensional DCT, which is given by:
whereNEWLINE
NEWLINE- is the horizontal spatial frequency
In mathematics, physics, and engineering, spatial frequency is a characteristic of any structure that is periodic across position in space. The spatial frequency is a measure of how often sinusoidal components of the structure repeat per unit of distance. The SI unit of spatial frequency is...
, for the integers . NEWLINE- is the vertical spatial frequency, for the integers .
NEWLINE-
NEWLINE
\alpha(u) =
\begin{cases}
\sqrt{ \frac{1}{8} }, & \mbox{if }u=0 \\
\sqrt{ \frac{2}{8} }, & \mbox{otherwise}
\end{cases}
is a normalizing scale factor to make the transformation orthonormalNEWLINE
NEWLINE- is the pixel value at coordinates
NEWLINE- is the DCT coefficient at coordinates
NEWLINE
If we perform this transformation on our matrix above, we get the following (rounded to the nearest two digits beyond the decimal point):
Note the top-left corner entry with the rather large magnitude. This is the DC coefficient. The remaining 63 coefficients are called the AC coefficients. The advantage of the DCT is its tendency to aggregate most of the signal in one corner of the result, as may be seen above. The quantization step to follow accentuates this effect while simultaneously reducing the overall size of the DCT coefficients, resulting in a signal that is easy to compress efficiently in the entropy stage.
The DCT temporarily increases the bit-depth of the data, since the DCT coefficients of an 8-bit/component image take up to 11 or more bits (depending on fidelity of the DCT calculation) to store. This may force the codec to temporarily use 16-bit bins to hold these coefficients, doubling the size of the image representation at this point; they are typically reduced back to 8-bit values by the quantization step. The temporary increase in size at this stage is not a performance concern for most JPEG implementations, because typically only a very small part of the image is stored in full DCT form at any given time during the image encoding or decoding process.
Quantization
The human eye is good at seeing small differences in
brightnessBrightness is an attribute of visual perception in which a source appears to be radiating or reflecting light. In other words, brightness is the perception elicited by the luminance of a visual target...
over a relatively large area, but not so good at distinguishing the exact strength of a high frequency brightness variation. This allows one to greatly reduce the amount of information in the high frequency components. This is done by simply dividing each component in the frequency domain by a constant for that component, and then rounding to the nearest integer. This rounding operation is the only lossy operation in the whole process if the DCT computation is performed with sufficiently high precision. As a result of this, it is typically the case that many of the higher frequency components are rounded to zero, and many of the rest become small positive or negative numbers, which take many fewer bits to represent.
A typical quantization matrix, as specified in the original JPEG Standard, is as follows:
The quantized DCT coefficients are computed with
where
is the unquantized DCT coefficients;
is the quantization matrix above; and
is the quantized DCT coefficients.
Using this quantization matrix with the DCT coefficient matrix from above results in:
For example, using −415 (the DC coefficient) and rounding to the nearest integer