To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.

Lossy compression

From Wikipedia, the free encyclopedia

Low compression (high quality) JPEG
High compression (low quality) JPEG

In information technology, lossy compression or irreversible compression is the class of data encoding methods that uses inexact approximations and partial data discarding to represent the content. These techniques are used to reduce data size for storing, handling, and transmitting content. The different versions of the photo of the cat to the right show how higher degrees of approximation create coarser images as more details are removed. This is opposed to lossless data compression (reversible data compression) which does not degrade the data. The amount of data reduction possible using lossy compression is much higher than through lossless techniques.

Well-designed lossy compression technology often reduces file sizes significantly before degradation is noticed by the end-user. Even when noticeable by the user, further data reduction may be desirable (e.g., for real-time communication, to reduce transmission times, or to reduce storage needs).

Lossy compression is most commonly used to compress multimedia data (audio, video, and images), especially in applications such as streaming media and internet telephony. By contrast, lossless compression is typically required for text and data files, such as bank records and text articles. It can be advantageous to make a master lossless file which can then be used to produce additional copies from. This allows one to avoid basing new compressed copies off of a lossy source file, which would yield additional artifacts and further unnecessary information loss.

YouTube Encyclopedic

  • 1/5
    179 963
    14 457
    8 492
    13 626
    14 731
  • ✪ Compression: Crash Course Computer Science #21
  • ✪ Lossy vs. Lossless Compression
  • ✪ Data Compression Introduction, Data Compression Types(Lossless, Lossy), Imp Terms - CGMM Hindi
  • ✪ Lossy and Lossless (RLE) Compression


This episode is brought to you by Curiosity Stream. Hi, I'm Carrie Anne, and welcome to Crash Course Computer Science! Last episode we talked about Files, bundles of data, stored on a computer, that are formatted and arranged to encode information, like text, sound or images. We even discussed some basic file formats, like text, wave, and bitmap. While these formats are perfectly fine and still used today, their simplicity also means they’re not very efficient. Ideally, we want files to be as small as possible, so we can store lots of them without filling up our hard drives, and also transmit them more quickly. Nothing is more frustrating than waiting for an email attachment to download. Ugh! The answer is compression, which literally squeezes data into a smaller size. To do this, we have to encode data using fewer bits than the original representation. That might sound like magic, but it’s actually computer science! INTRO Lets return to our old friend from last episode, Mr. Pac-man! This image is 4 pixels by 4 pixels. As we discussed, image data is typically stored as a list of pixel values. To know where rows end, image files have metadata, which defines properties like dimensions. But, to keep it simple today, we’re not going to worry about it. Each pixel’s color is a combination of three additive primary colors: red, green and blue. We store each of those values in one byte, giving us a range of 0 to 255 for each color. If you mix full intensity red, green and blue - that’s 255 for all three values - you get the color white. If you mix full intensity red and green, but no blue (it’s 0), you get yellow. We have 16 pixels in our image, and each of those needs 3 bytes of color data. That means this image’s data will consume 48 bytes of storage. But, we can compress the data and pack it into a smaller number of bytes than 48! One way to compress data is to reduce repeated or redundant information. The most straightforward way to do this is called Run-Length Encoding. This takes advantage of the fact that there are often runs of identical values in files. For example, in our pac-man image, there are 7 yellow pixels in a row. Instead of encoding redundant data: yellow pixel, yellow pixel, yellow pixel, and so on, we can just say “there’s 7 yellow pixels in a row” by inserting an extra byte that specifies the length of the run, like so: And then we can eliminate the redundant data behind it. To ensure that computers don’t get confused with which bytes are run lengths and which bytes represent color, we have to be consistent in how we apply this scheme. So, we need to preface all pixels with their run-length. In some cases, this actually adds data, but on the whole, we’ve dramatically reduced the number of bytes we need to encode this image. We’re now at 24 bytes, down from 48. That’s 50% smaller! A huge saving! Also note that we haven’t lost any data. We can easily expand this back to the original form without any degradation. A compression technique that has this characteristic is called lossless compression, because we don’t lose anything. The decompressed data is identical to the original before compression, bit for bit. Let's take a look at another type of lossless compression, where blocks of data are replaced by more compact representations. This is sort of like “don’t forget to be awesome” being replaced by DFTBA. To do this, we need a dictionary that stores the mapping from codes to data. Lets see how this works for our example. We can view our image as not just a string of individual pixels, but as little blocks of data. For simplicity, we’re going to use pixel pairs, which are 6 bytes long, but blocks can be any size. In our example, there are only four pairings: White-yellow, black-yellow, yellow-yellow and white-white. Those are the data blocks in our dictionary we want to generate compact codes for. What’s interesting, is that these blocks occur at different frequencies. There are 4 yellow-yellow pairs, 2 white-yellow pairs, and 1 each of black-yellow and white-white. Because yellow-yellow is the most common block, we want that to be substituted for the most compact representation. On the other hand, black-yellow and white-white, can be substituted for something longer because those blocks are infrequent. One method for generating efficient codes is building a Huffman Tree, invented by David Huffman while he was a student at MIT in the 1950s. His algorithm goes like this. First, you layout all the possible blocks and their frequencies. At every round, you select the two with the lowest frequencies. Here, that’s Black-Yellow and White-White, each with a frequency of 1. You combine these into a little tree... ...which have a combined frequency of 2, so we record that. And now one step of the algorithm done. Now we repeat the process. This time we have three things to choose from. Just like before, we select the two with the lowest frequency, put them into a little tree, and record the new total frequency of all the sub items. Ok, we’re almost done. This time it’s easy to select the two items with the lowest frequency because there are only two things left to pick. We combine these into a tree, and now we’re done! Our tree looks like this, and it has a very cool property: it’s arranged by frequency, with less common items lower down. So, now we have a tree, but you may be wondering how this gets us to a dictionary. Well, we use our frequency-sorted tree to generate the codes we need by labeling each branch with a 0 or a 1, like so: With this, we can write out our code dictionary. Yellow-yellow is encoded as just a single 0. White-yellow is encoded as 1 0 (“one zero”) Black-Yellow is 1 1 0 and finally white-white is 1 1 1. The really cool thing about these codewords is that there’s no way to have conflicting codes, because each path down the tree is unique. This means our codes are prefix-free, that is no code starts with another complete code. Now, let’s return to our image data and compress it! Our first pixel pair, white-yellow, is substituted for the bits “1 0”. The next pair is black-yellow, which is substituted for “1 1 0”. Next is yellow-yellow with the incredibly compact substitution of just “0”. And this process repeats for the rest of the image: So instead of 48 bytes of image data ...this process has encoded it into 14 bits -- NOT BYTES -- BITS!! That’s less than 2 bytes of data! But, don’t break out the champagne quite yet! This data is meaningless unless we also save our code dictionary. So, we’ll need to append it to the front of the image data, like this. Now, including the dictionary, our image data is 30 bytes long. That’s still a significant improvement over 48 bytes. The two approaches we discussed, removing redundancies and using more compact representations, are often combined, and underlie almost all lossless compressed file formats, like GIF, PNG, PDF and ZIP files. Both run-length encoding and dictionary coders are lossless compression techniques. No information is lost; when you decompress, you get the original file. That’s really important for many types of files. Like, it’d be very odd if I zipped up a word document to send to you, and when you decompressed it on your computer, the text was different. But, there are other types of files where we can get away with little changes, perhaps by removing unnecessary or less important information, especially information that human perception is not good at detecting. And this trick underlies most lossy compression techniques. These tend to be pretty complicated, so we’re going to attack this at a conceptual level. Let’s take sound as an example. Your hearing is not perfect. We can hear some frequencies of sound better than others. And there are some we can’t hear at all, like ultrasound. Unless you’re a bat. Basically, if we make a recording of music, and there’s data in the ultrasonic frequency range, we can discard it, because we know that humans can’t hear it. On the other hand, humans are very sensitive to frequencies in the vocal range, like people singing, so it’s best to preserve quality there as much as possible. Deep bass is somewhere in between. Humans can hear it, but we’re less attuned to it. We mostly sense it. Lossy audio compressors takes advantage of this, and encode different frequency bands at different precisions. Even if the result is rougher, it’s likely that users won’t perceive the difference. Or at least it doesn’t dramatically affect the experience. And here comes the hate mail from the audiophiles! You encounter this type of audio compression all the time. It’s one of the reasons you sound different on a cellphone versus in person. The audio data is being compressed, allowing more people to take calls at once. As the signal quality or bandwidth get worse, compression algorithms remove more data, further reducing precision, which is why Skype calls sometimes sound like robots talking. Compared to an uncompressed audio format, like a WAV or FLAC (there we go, got the audiophiles back) compressed audio files, like MP3s, are often 10 times smaller. That’s a huge saving! And it’s why I’ve got a killer music collection on my retro iPod. Don’t judge. This idea of discarding or reducing precision in a manner that aligns with human perception is called perceptual coding, and it relies on models of human perception, which come from a field of study called Psychophysics. This same idea is the basis of lossy compressed image formats, most famously JPEGs. Like hearing, the human visual system is imperfect. We’re really good at detecting sharp contrasts, like the edges of objects, but our perceptual system isn’t so hot with subtle color variations. JPEG takes advantage of this by breaking images up into blocks of 8x8 pixels, then throwing away a lot of the high-frequency spatial data. For example, take this photo of our directors dog - Noodle. So cute! Let’s look at patch of 8x8 pixels. Pretty much every pixel is different from its neighbor, making it hard to compress with loss-less techniques because there’s just a lot going on. Lots of little details. But human perception doesn’t register all those details. So, we can discard a lot of that detail, and replace it with a simplified patch like this. This maintains the visual essence, but might only use 10% of the data. We can do this for all the patches in the image and get this result. You can still see it’s a dog, but the image is rougher. So, that’s an extreme example, going from a slightly compressed JPEG to a highly compressed one, one-eighth the original file size. Often, you can get away with a quality somewhere in between, and perceptually, it’s basically the same as the original. The one on the left is one-third the file size of the one on the right. That’s a big savings for essentially the same thing. Can you tell the difference between the two? Probably not, but I should mention that video compression plays a role in that too, since I’m literally being compressed in a video right now. Videos are really just long sequences of images, so a lot of what I said about them applies here too. But videos can do some extra clever stuff, because between frames, a lot of pixels are going to be the same. Like this whole background behind me! This is called temporal redundancy. We don’t need to re-transmit those pixels every frame of the video. We can just copy patches of data forward. When there are small pixel differences, like the readout on this frequency generator behind me, most video formats send data that encodes just the difference between patches, which is more efficient than re-transmitting all the pixels afresh, again taking advantage of inter-frame similarity. The fanciest video compression formats go one step further. They find patches that are similar between frames, and not only copy them forward, with or without differences, but also can apply simple effects to them, like a shift or rotation. They can also lighten or darken a patch between frames. So, if I move my hand side to side like this the video compressor will identify the similarity, capture my hand in one or more patches, then just move these patches around between frames. You’re actually seeing my hand from the past… kinda freaky, but it uses a lot less data. MPEG-4 videos, a common standard, are often 20 to 200 times smaller than the original, uncompressed file. However, encoding frames as translations and rotations of patches from previous frames can go horribly wrong when you compress too heavily, and there isn’t enough space to update pixel data inside of the patches. The video player will forge ahead, applying the right motions, even if the patch data is wrong. And this leads to some hilarious and trippy effects, which I’m sure you’ve seen. Overall, it’s extremely useful to have compression techniques for all the types of data I discussed today. (I guess our imperfect vision and hearing are “useful,” too.) And it’s important to know about compression because it allows users to store pictures, music, and videos in efficient ways. Without it, streaming your favorite Carpool Karaoke videos on YouTube would be nearly impossible, due to bandwidth and the economics of transmitting that volume of data for free. And now when your Skype calls sound like they’re being taken over by demons, you’ll know what’s really going on. I’ll see you next week. Hey guys, this week’s episode was brought to you by CuriosityStream which is a streaming service full of documentaries and non­fiction titles from some really great filmmakers, including exclusive originals. Now I normally give computer science recommendations since this is Crash Course Computer Science and all and Curiosity Stream has a ton of great ones. But you absolutely have to check out “Miniverse” starring everyone’s favorite space-station-singing-Canadian astronaut, Chris Hadfield, as he takes a roadtrip across the Solar System scaled down the the size of the United States. It’s basically 50 minutes of Chris and his passengers geeking out about our amazing planetary neighbors and you don’t want to miss it. So get unlimited access today, and your first two months are free if you sign up at and use the promo code "crashcourse" during the sign up process.



It is possible to compress many types of digital data in a way that reduces the size of a computer file needed to store it, or the bandwidth needed to transmit it, with no loss of the full information contained in the original file. A picture, for example, is converted to a digital file by considering it to be an array of dots and specifying the color and brightness of each dot. If the picture contains an area of the same color, it can be compressed without loss by saying "200 red dots" instead of "red dot, red dot, ...(197 more times)..., red dot."

The original data contains a certain amount of information, and there is a lower limit to the size of file that can carry all the information. Basic information theory says that there is an absolute limit in reducing the size of this data. When data is compressed, its entropy increases, and it cannot increase indefinitely. As an intuitive example, most people know that a compressed ZIP file is smaller than the original file, but repeatedly compressing the same file will not reduce the size to nothing. Most compression algorithms can recognize when further compression would be pointless and would in fact increase the size of the data.

In many cases, files or data streams contain more information than is needed for a particular purpose. For example, a picture may have more detail than the eye can distinguish when reproduced at the largest size intended; likewise, an audio file does not need a lot of fine detail during a very loud passage. Developing lossy compression techniques as closely matched to human perception as possible is a complex task. Sometimes the ideal is a file that provides exactly the same perception as the original, with as much digital information as possible removed; other times, perceptible loss of quality is considered a valid trade-off for the reduced data.

The terms 'irreversible' and 'reversible' are preferred over 'lossy' and 'lossless' respectively for some applications, such as medical image compression, to circumvent the negative implications of 'loss'. The type and amount of loss can affect the utility of the images. Artifacts or undesirable effects of compression may be clearly discernible yet the result still useful for the intended purpose. Or lossy compressed images may be 'visually lossless', or in the case of medical images, so-called Diagnostically Acceptable Irreversible Compression (DAIC)[1] may have been applied.

Transform coding

More generally, some forms of lossy compression can be thought of as an application of transform coding – in the case of multimedia data, perceptual coding: it transforms the raw data to a domain that more accurately reflects the information content. For example, rather than expressing a sound file as the amplitude levels over time, one may express it as the frequency spectrum over time, which corresponds more accurately to human audio perception. While data reduction (compression, be it lossy or lossless) is a main goal of transform coding, it also allows other goals: one may represent data more accurately for the original amount of space[2] – for example, in principle, if one starts with an analog or high-resolution digital master, an MP3 file of a given size should provide a better representation than a raw uncompressed audio in WAV or AIFF file of the same size. This is because uncompressed audio can only reduce file size by lowering bit rate or depth, whereas compressing audio can reduce size while maintaining bit rate and depth. This compression becomes a selective loss of the least significant data, rather than losing data across the board. Further, a transform coding may provide a better domain for manipulating or otherwise editing the data – for example, equalization of audio is most naturally expressed in the frequency domain (boost the bass, for instance) rather than in the raw time domain.

From this point of view, perceptual encoding is not essentially about discarding data, but rather about a better representation of data. Another use is for backward compatibility and graceful degradation: in color television, encoding color via a luminance-chrominance transform domain (such as YUV) means that black-and-white sets display the luminance, while ignoring the color information. Another example is chroma subsampling: the use of color spaces such as YIQ, used in NTSC, allow one to reduce the resolution on the components to accord with human perception – humans have highest resolution for black-and-white (luma), lower resolution for mid-spectrum colors like yellow and green, and lowest for red and blues – thus NTSC displays approximately 350 pixels of luma per scanline, 150 pixels of yellow vs. green, and 50 pixels of blue vs. red, which are proportional to human sensitivity to each component.

Information loss

Lossy compression formats suffer from generation loss: repeatedly compressing and decompressing the file will cause it to progressively lose quality. This is in contrast with lossless data compression, where data will not be lost via the use of such a procedure. Information-theoretical foundations for lossy data compression are provided by rate-distortion theory. Much like the use of probability in optimal coding theory, rate-distortion theory heavily draws on Bayesian estimation and decision theory in order to model perceptual distortion and even aesthetic judgment.

There are two basic lossy compression schemes:

  • In lossy transform codecs, samples of picture or sound are taken, chopped into small segments, transformed into a new basis space, and quantized. The resulting quantized values are then entropy coded.
  • In lossy predictive codecs, previous and/or subsequent decoded data is used to predict the current sound sample or image frame. The error between the predicted data and the real data, together with any extra information needed to reproduce the prediction, is then quantized and coded.

In some systems the two techniques are combined, with transform codecs being used to compress the error signals generated by the predictive stage.


The advantage of lossy methods over lossless methods is that in some cases a lossy method can produce a much smaller compressed file than any lossless method, while still meeting the requirements of the application. Lossy methods are most often used for compressing sound, images or videos. This is because these types of data are intended for human interpretation where the mind can easily "fill in the blanks" or see past very minor errors or inconsistencies – ideally lossy compression is transparent (imperceptible), which can be verified via an ABX test. Data files using lossy compression are smaller in size and thus cost less to store and to transmit over the Internet, a crucial consideration for streaming video services such as Netflix and streaming audio services such as Spotify.

Emotional effects

A study conducted by the Audio Engineering Library concluded that lossy compression formats such as MP3s have distinct effects on timbral and emotional characteristics, tending to strengthen negative emotional qualities and weaken positive ones.[3] The study further noted that the trumpet is the instrument most affected by compression, while the horn is least.


When a user acquires a lossily compressed file, (for example, to reduce download time) the retrieved file can be quite different from the original at the bit level while being indistinguishable to the human ear or eye for most practical purposes. Many compression methods focus on the idiosyncrasies of human physiology, taking into account, for instance, that the human eye can see only certain wavelengths of light. The psychoacoustic model describes how sound can be highly compressed without degrading perceived quality. Flaws caused by lossy compression that are noticeable to the human eye or ear are known as compression artifacts.

Compression ratio

The compression ratio (that is, the size of the compressed file compared to that of the uncompressed file) of lossy video codecs is nearly always far superior to that of the audio and still-image equivalents.

  • Video can be compressed immensely (e.g. 100:1) with little visible quality loss
  • Audio can often be compressed at 10:1 with imperceptible loss of quality
  • Still images are often lossily compressed at 10:1, as with audio, but the quality loss is more noticeable, especially on closer inspection.

Transcoding and editing

An important caveat about lossy compression (formally transcoding), is that editing lossily compressed files causes digital generation loss from the re-encoding. This can be avoided by only producing lossy files from (lossless) originals and only editing (copies of) original files, such as images in raw image format instead of JPEG. If data which has been compressed lossily is decoded and compressed losslessly, the size of the result can be comparable with the size of the data before lossy compression, but the data already lost cannot be recovered. When deciding to use lossy conversion without keeping the original, one should remember that format conversion may be needed in the future to achieve compatibility with software or devices (format shifting), or to avoid paying patent royalties for decoding or distribution of compressed files.

Editing of lossy files

By modifying the compressed data directly without decoding and re-encoding, some editing of lossily compressed files without degradation of quality is possible. Editing which reduces the file size as if it had been compressed to a greater degree, but without more loss than this, is sometimes also possible.


The primary programs for lossless editing of JPEGs are jpegtran, and the derived exiftran (which also preserves Exif information), and Jpegcrop (which provides a Windows interface).

These allow the image to be

While unwanted information is destroyed, the quality of the remaining portion is unchanged.

Some other transforms are possible to some extent, such as joining images with the same encoding (composing side by side, as on a grid) or pasting images (such as logos) onto existing images (both via Jpegjoin), or scaling.[4]

Some changes can be made to the compression without re-encoding:

  • optimizing the compression (to reduce size without change to the decoded image)
  • converting between progressive and non-progressive encoding.

The freeware Windows-only IrfanView has some lossless JPEG operations in its JPG_TRANSFORM plugin.


Metadata, such as ID3 tags, Vorbis comments, or Exif information, can usually be modified or removed without modifying the underlying data.

Downsampling/compressed representation scalability

One may wish to downsample or otherwise decrease the resolution of the represented source signal and the quantity of data used for its compressed representation without re-encoding, as in bitrate peeling, but this functionality is not supported in all designs, as not all codecs encode data in a form that allows less important detail to simply be dropped. Some well-known designs that have this capability include JPEG 2000 for still images and H.264/MPEG-4 AVC based Scalable Video Coding for video. Such schemes have also been standardized for older designs as well, such as JPEG images with progressive encoding, and MPEG-2 and MPEG-4 Part 2 video, although those prior schemes had limited success in terms of adoption into real-world common usage. Without this capacity, which is often the case in practice, to produce a representation with lower resolution or lower fidelity than a given one, one needs to start with the original source signal and encode, or start with a compressed representation and then decompress and re-encode it (transcoding), though the latter tends to cause digital generation loss.

Another approach is to encode the original signal at several different bitrates, and their either choose which to use (as when streaming over the internet – as in RealNetworks' "SureStream" – or offering varying downloads, as at Apple's iTunes Store), or broadcast several, where the best that is successfully received is used, as in various implementations of hierarchical modulation. Similar techniques are used in mipmaps, pyramid representations, and more sophisticated scale space methods. Some audio formats feature a combination of a lossy format and a lossless correction which when combined reproduce the original signal; the correction can be stripped, leaving a smaller, lossily compressed, file. Such formats include MPEG-4 SLS (Scalable to Lossless), WavPack, OptimFROG DualStream, and DTS-HD Master Audio in lossless (XLL) mode




3D computer graphics



  • Opus (mostly for real-time applications)



Other data

Researchers have (semi-seriously) performed lossy compression on text by either using a thesaurus to substitute short words for long ones, or generative text techniques,[8] although these sometimes fall into the related category of lossy data conversion.

Lowering resolution

A general kind of lossy compression is to lower the resolution of an image, as in image scaling, particularly decimation. One may also remove less "lower information" parts of an image, such as by seam carving. Many media transforms, such as Gaussian blur, are, like lossy compression, irreversible: the original signal cannot be reconstructed from the transformed signal. However, in general these will have the same size as the original, and are not a form of compression. Lowering resolution has practical uses, as the NASA New Horizons craft will transmit thumbnails of its encounter with Pluto-Charon before it sends the higher resolution images. Another solution for slow connections is the usage of Image interlacing which progressively defines the image. Thus a partial transmission is enough to preview the final image, in a lower resolution version, without creating a scaled and a full version too.

See also


  1. ^ European Society of Radiology (2011). "Usability of irreversible image compression in radiological imaging. A position paper by the European Society of Radiology (ESR)". Insights Imaging. 2: 103–115. doi:10.1007/s13244-011-0071-x. PMC 3259360. PMID 22347940.
  2. ^ “Although one main goal of digital audio perceptual coders is data reduction, this is not a necessary characteristic. As we shall see, perceptual coding can be used to improve the representation of digital audio through advanced bit allocation.” Masking and Perceptual Coding, Victor Lombardi
  3. ^ "MP3s make you less happy, study says". What Hi Fi?. What Hi Fi?. Dec 5, 2016. Retrieved December 17, 2018.
  4. ^ New jpegtran features
  5. ^ "aptX HD - lossless or lossy?". AVHub. 2016-11-22. Retrieved 2018-01-13.
  6. ^ Darko, John H. (2017-03-29). "The inconvenient truth about Bluetooth audio". DAR__KO. Retrieved 2018-01-13.
  7. ^ "What is Sony LDAC, and how does it do it?". AVHub. 2015-08-24. Retrieved 2018-01-13.
  8. ^ I. H. WITTEN; et al. "Semantic and Generative Models for Lossy Text Compression" (PDF). The Computer Journal. Retrieved 2007-10-13.

External links

This page was last edited on 19 April 2019, at 21:13
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.