home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / compress / 4426 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  46.2 KB

  1. Xref: sparky comp.compression:4426 news.answers:5023
  2. Path: sparky!uunet!mcsun!julienas!chorus!chorus.fr
  3. From: jloup@chorus.fr (Jean-loup Gailly)
  4. Newsgroups: comp.compression,news.answers
  5. Subject: comp.compression Frequently Asked Questions (part 2/3)
  6. Summary: *** READ THIS BEFORE POSTING ***
  7. Keywords: data compression, FAQ
  8. Message-ID: <compr2_7jan93@chorus.fr>
  9. Date: 7 Jan 93 18:16:13 GMT
  10. Expires: 15 Feb 93 16:17:20 GMT
  11. References: <compr1_5jan93@chorus.fr>
  12. Sender: news@chorus.chorus.fr
  13. Reply-To: jloup@chorus.fr
  14. Followup-To: comp.compression
  15. Lines: 930
  16. Approved: news-answers-request@MIT.Edu
  17. Supersedes: <compr2_5jan93@chorus.fr>
  18.  
  19. Archive-name: compression-faq/part2
  20. Last-modified: Jan 5th, 1993
  21.  
  22. This file is part 2 of a set of Frequently Asked Questions for the
  23. groups comp.compression and comp.compression.research.
  24. If you did not get part 1 or 3, you can get them by ftp
  25. on rtfm.mit.edu [18.72.1.58] in directory
  26.    /pub/usenet/news.answers/compression-faq
  27.  
  28. It looks as if this part 2 (sent on Jan 5th) got lost again,
  29. so I am sending it for the second time (Jan 7th). Sorry.
  30.  
  31. If you don't want to see this FAQ regularly, please add the subject
  32. line to your kill file. If you have corrections or suggestions for
  33. this FAQ, send them to Jean-loup Gailly <jloup@chorus.fr>.  Thank you.
  34.  
  35. Contents
  36. ========
  37.  
  38. Part 2: (Long) introductions to data compression techniques
  39.  
  40. [70] Introduction to data compression (long)
  41.        Huffman and Related Compression Techniques
  42.        Arithmetic Coding
  43.        Substitutional Compressors
  44.           The LZ78 family of compressors
  45.           The LZ77 family of compressors
  46.  
  47. [71] Introduction to MPEG (long)
  48.        What is MPEG?
  49.        Does it have anything to do with JPEG?
  50.        Then what's JBIG and MHEG?
  51.        What has MPEG accomplished?
  52.        So how does MPEG I work?
  53.        What about the audio compression?
  54.        So how much does it compress?
  55.        What's phase II?
  56.        When will all this be finished?
  57.        How do I join MPEG?
  58.        How do I get the documents, like the MPEG I draft?
  59.  
  60. [72] What is wavelet theory?
  61. [73] What is the theoretical compression limit?
  62. [74] Introduction to JBIG
  63.  
  64.  
  65. Part 3: (Long) list of image compression hardware
  66.  
  67. [85] Image compression hardware
  68. [99] Acknowledgments
  69.  
  70.  
  71. Search for "Subject: [#]" to get to question number # quickly. Some news
  72. readers can also take advantage of the message digest format used here.
  73.  
  74. ------------------------------------------------------------------------------
  75.  
  76. Subject: [70] Introduction to data compression (long)
  77.  
  78.  
  79. Written by Peter Gutmann <pgut1@cs.aukuni.ac.nz>.
  80.  
  81.  Huffman and Related Compression Techniques
  82.  ------------------------------------------
  83.  
  84.   *Huffman compression* is a statistical data compression technique which 
  85. gives a reduction in the average code length used to represent the symbols of 
  86. a alphabet.  The Huffman code is an example of a code which is optimal in the 
  87. case where all symbols probabilities are integral powers of 1/2.  A Huffman 
  88. code can be built in the following manner:
  89.  
  90.   (1) Rank all symbols in order of probability of occurrence.
  91.     
  92.   (2) Successively combine the two symbols of the lowest probability to form
  93.       a new composite symbol; eventually we will build a binary tree where
  94.       each node is the probability of all nodes beneath it.
  95.  
  96.   (3) Trace a path to each leaf, noticing the direction at each node.
  97.  
  98.   For a given frequency distribution, there are many possible Huffman codes,
  99. but the total compressed length will be the same. It is possible to
  100. define a 'canonical' Huffman tree, that is, pick one of these alternative
  101. trees. Such a canonical tree can then be represented very compactly, by
  102. transmitting only the bit length of each code. This technique is used
  103. in most archivers (pkzip, lha, zoo, arj, ...).
  104.  
  105.  
  106.   A technique related to Huffman coding is *Shannon-Fano coding*, which was 
  107. suggested by Shannon and Weaver in 1949 and modified by Fano in 1961.  It 
  108. works as follows:
  109.  
  110.   (1) Divide the set of symbols into two equal or almost equal subsets
  111.       based on the probability of occurrence of characters in each
  112.       subset.  The first subset is assigned a binary zero, the second
  113.       a binary one.
  114.  
  115.   (2) Repeat step (1) until all subsets have a single element.
  116.  
  117. The algorithm used to create the Huffman codes is bottom-up, and the
  118. one for the Shannon-Fano codes is top-down. Huffman encoding always
  119. generates optimal codes, Shannon-Fano sometimes uses a few more bits.
  120.  
  121.  
  122.  Arithmetic Coding
  123.  -----------------
  124.  
  125.   It would appear that Huffman or Shannon-Fano coding is the perfect
  126. means of compressing data.  However, this is *not* the case.  As
  127. mentioned above, these coding methods are optimal when and only when
  128. the symbol probabilities are integral powers of 1/2, which is usually
  129. not the case.
  130.  
  131.   The technique of *arithmetic coding* does not have this restriction:
  132. It achieves the same effect as treating the message as one single unit
  133. (a technique which would, for Huffman coding, require enumeration of
  134. every single possible message), and thus attains the theoretical
  135. entropy bound to compression efficiency for any source.
  136.  
  137.   Arithmetic coding works by representing a number by an interval of real 
  138. numbers between 0 and 1.  As the message becomes longer, the interval needed 
  139. to represent it becomes smaller and smaller, and the number of bits needed to 
  140. specify that interval increases.  Successive symbols in the message reduce 
  141. this interval in accordance with the probability of that symbol. The more
  142. likely symbols reduce the range by less, and thus add fewer bits to the   
  143. message.
  144.  
  145.      1                                             Codewords
  146.     +-----------+-----------+-----------+           /-----\
  147.     |           |8/9 YY     |  Detail   |<- 31/32    .11111
  148.     |           +-----------+-----------+<- 15/16    .1111
  149.     |    Y      |           | too small |<- 14/16    .1110
  150.     |2/3        |    YX     | for text  |<- 6/8      .110
  151.     +-----------+-----------+-----------+
  152.     |           |           |16/27 XYY  |<- 10/16    .1010
  153.     |           |           +-----------+
  154.     |           |    XY     |           |
  155.     |           |           |   XYX     |<- 4/8      .100
  156.     |           |4/9        |           |
  157.     |           +-----------+-----------+
  158.     |           |           |           |
  159.     |    X      |           |   XXY     |<- 3/8      .011
  160.     |           |           |8/27       |
  161.     |           |           +-----------+
  162.     |           |    XX     |           |
  163.     |           |           |           |<- 1/4      .01
  164.     |           |           |   XXX     |
  165.     |           |           |           |
  166.     |0          |           |           |
  167.     +-----------+-----------+-----------+
  168.  
  169.   As an example of arithmetic coding, lets consider the example of two
  170. symbols X and Y, of probabilities 0.66 and 0.33. To encode this message, we
  171. examine the first symbol: If it is a X, we choose the lower partition; if
  172. it is a Y, we choose the upper partition.  Continuing in this manner for
  173. three symbols, we get the codewords shown to the right of the diagram above
  174. - they can be found by simply taking an appropriate location in the
  175. interval for that particular set of symbols and turning it into a binary
  176. fraction. In practice, it is also necessary to add a special end-of-data
  177. symbol, which is not represented in this simpe example.
  178.         
  179.   In this case the arithmetic code is not completely efficient, which is due 
  180. to the shortness of the message - with longer messages the coding efficiency 
  181. does indeed approach 100%.
  182.  
  183.   Now that we have an efficient encoding technique, what can we do with it? 
  184. What we need is a technique for building a model of the data which we can 
  185. then use with the encoder.  The simplest model is a fixed one, for example a 
  186. table of standard letter frequencies for English text which we can then use 
  187. to get letter probabilities.  An improvement on this technique is to use an 
  188. *adaptive model*, in other words a model which adjusts itself to the data 
  189. which is being compressed as the data is compressed.  We can convert the 
  190. fixed model into an adaptive one by adjusting the symbol frequencies after 
  191. each new symbol is encoded, allowing the model to track the data being 
  192. transmitted.  However, we can do much better than that.
  193.  
  194. Using the symbol probabilities by themselves is not a particularly good
  195. estimate of the true entropy of the data: We can take into account
  196. intersymbol probabilities as well.  The best compressors available today
  197. take this approach: DMC (Dynamic Markov Coding) starts with a zero-order
  198. Markov model and gradually extends this initial model as compression
  199. progresses; PPM (Prediction by Partial Matching) looks for a match of the
  200. text to be compressed in an order-n context.  If no match is found, it
  201. drops to an order n-1 context, until it reaches order 0.  Both these
  202. techniques thus obtain a much better model of the data to be compressed,
  203. which, combined with the use of arithmetic coding, results in superior
  204. compression performance.
  205.  
  206.   So if arithmetic coding-based compressors are so powerful, why are they not 
  207. used universally?  Apart from the fact that they are relatively new and 
  208. haven't come into general use too much yet, there is also one major concern:  
  209. The fact that they consume rather large amounts of computing resources, both 
  210. in terms of CPU power and memory.  The building of sophisticated models for 
  211. the compression can chew through a fair amount of memory (especially in the 
  212. case of DMC, where the model can grow without bounds); and the arithmetic 
  213. coding itself involves a fair amount of number crunching.
  214. There is however an alternative approach, a class of compressors generally 
  215. referred to as *substitutional* or *dictionary-based compressors*.
  216.  
  217.  Substitutional Compressors
  218.  --------------------------
  219.  
  220.   The basic idea behind a substitutional compressor is to replace an 
  221. occurrence of a particular phrase or group of bytes in a piece of data with a 
  222. reference to a previous occurrence of that phrase.  There are two main 
  223. classes of schemes, named after Jakob Ziv and Abraham Lempel, who first 
  224. proposed them in 1977 and 1978.
  225.  
  226. <The LZ78 family of compressors>
  227.  
  228.   LZ78-based schemes work by entering phrases into a *dictionary* and then, 
  229. when a repeat occurrence of that particular phrase is found, outputting the 
  230. dictionary index instead of the phrase.  There exist several compression 
  231. algorithms based on this principle, differing mainly in the manner in which 
  232. they manage the dictionary.  The most well-known scheme (in fact the most 
  233. well-known of all the Lempel-Ziv compressors, the one which is generally (and 
  234. mistakenly) referred to as "Lempel-Ziv Compression"), is Terry Welch's LZW 
  235. scheme, which he designed in 1984 for implementation in hardware for high- 
  236. performance disk controllers.
  237.  
  238. Input string: /WED/WE/WEE/WEB
  239.  
  240. Character input:    Code output:    New code value and associated string:
  241.     /W                  /                   256 = /W
  242.     E                   W                   257 = WE
  243.     D                   E                   258 = ED
  244.     /                   D                   259 = D/
  245.     WE                  256                 260 = /WE
  246.     /                   E                   261 = E/
  247.     WEE                 260                 262 = /WEE
  248.     /W                  261                 263 = E/W
  249.     EB                  257                 264 = WEB
  250.     <END>               B
  251.     
  252.   LZW starts with a 4K dictionary, of which entries 0-255 refer to individual 
  253. bytes, and entries 256-4095 refer to substrings.  Each time a new code is 
  254. generated it means a new string has been parsed.  New strings are generated 
  255. by appending the current character K to the end of an existing string w.  The 
  256. algorithm for LZW compression is as follows:
  257.  
  258.   set w = NIL
  259.   loop
  260.       read a character K
  261.       if wK exists is in the dictionary
  262.           w = wK
  263.       else
  264.           output the code for w
  265.           add wK to the string table
  266.           w = K
  267.   endloop
  268.  
  269.   A sample run of LZW over a (highly redundant) input string can be seen in 
  270. the diagram above.  The strings are built up character-by-character starting 
  271. with a code value of 256.  LZW decompression takes the stream of codes and 
  272. uses it to exactly recreate the original input data.  Just like the 
  273. compression algorithm, the decompressor adds a new string to the dictionary 
  274. each time it reads in a new code.  All it needs to do in addition is to 
  275. translate each incoming code into a string and send it to the output.  A 
  276. sample run of the LZW decompressor is shown in below.
  277.  
  278. Input code: /WED<256>E<260><261><257>B
  279.  
  280. Input code:        Output string:     New code value and associated string:
  281.     /                  /            
  282.     W                  W                      256 = /W
  283.     E                  E                      257 = WE
  284.     D                  D                      258 = ED
  285.     256                /W                     259 = D/
  286.     E                  E                      260 = /WE
  287.     260                /WE                    261 = E/
  288.     261                E/                     262 = /WEE
  289.     257                WE                     263 = E/W
  290.     B                  B                      264 = WEB
  291.            
  292.   The most remarkable feature of this type of compression is that the entire 
  293. dictionary has been transmitted to the decoder without actually explicitly 
  294. transmitting the dictionary.  At the end of the run, the decoder will have a 
  295. dictionary identical to the one the encoder has, built up entirely as part of 
  296. the decoding process.
  297.     LZW is more commonly encountered today in a variant known as LZC, after 
  298. its use in the UNIX "compress" program.  In this variant, pointers do not 
  299. have a fixed length.  Rather, they start with a length of 9 bits, and then 
  300. slowly grow to their maximum possible length once all the pointers of a 
  301. particular size have been used up.  Furthermore, the dictionary is not frozen 
  302. once it is full as for LZW - the program continually monitors compression 
  303. performance, and once this starts decreasing the entire dictionary is 
  304. discarded and rebuilt from scratch.  More recent schemes use some sort of 
  305. least-recently-used algorithm to discard little-used phrases once the 
  306. dictionary becomes full rather than throwing away the entire dictionary.  
  307.  
  308. Finally, not all schemes build up the dictionary by adding a single new 
  309. character to the end of the current phrase. An alternative technique is to 
  310. concatenate the previous two phrases (LZMW), which results in a faster 
  311. buildup of longer phrases than the character-by-character buildup of the 
  312. other methods.  The disadvantage of this method is that a more sophisticated 
  313. data structure is needed to handle the dictionary.
  314.  
  315. [A good introduction to LZW, MW, AP and Y coding is given in the yabba
  316. package. For ftp information, see question 2 in part one, file type .Y]
  317.  
  318.  
  319. <The LZ77 family of compressors>
  320.  
  321.   LZ77-based schemes keep track of the last n bytes of data seen, and when a 
  322. phrase is encountered that has already been seen, they output a pair of 
  323. values corresponding to the position of the phrase in the previously-seen 
  324. buffer of data, and the length of the phrase.  In effect the compressor moves 
  325. a fixed-size *window* over the data (generally referred to as a *sliding 
  326. window*), with the position part of the (position, length) pair referring to 
  327. the position of the phrase within the window.  The most commonly used 
  328. algorithms are derived from the LZSS scheme described by James Storer and 
  329. Thomas Szymanski in 1982.  In this the compressor maintains a window of size 
  330. N bytes and a *lookahead buffer* the contents of which it tries to find a 
  331. match for in the window:
  332.  
  333.   while( lookAheadBuffer not empty )
  334.       {
  335.       get a pointer ( position, match ) to the longest match in the window
  336.           for the lookahead buffer;
  337.  
  338.       if( length > MINIMUM_MATCH_LENGTH )
  339.           {
  340.           output a ( position, length ) pair;
  341.           shift the window length characters along;
  342.           }
  343.       else
  344.           {
  345.           output the first character in the lookahead buffer;
  346.           shift the window 1 character along;
  347.           }
  348.       }
  349.         
  350.   Decompression is simple and fast:  Whenever a ( position, length ) pair is 
  351. encountered, go to that ( position ) in the window and copy ( length ) bytes 
  352. to the output.
  353.  
  354.   Sliding-window-based schemes can be simplified by numbering the input text
  355. characters mod N, in effect creating a circular buffer.  The sliding window
  356. approach automatically creates the LRU effect which must be done explicitly in
  357. LZ78 schemes.  Variants of this method apply additional compression to the
  358. output of the LZSS compressor, which include a simple variable-length code
  359. (LZB), dynamic Huffman coding (LZH), and Shannon-Fano coding (ZIP 1.x)), all
  360. of which result in a certain degree of improvement over the basic scheme,
  361. especially when the data are rather random and the LZSS compressor has little
  362. effect.
  363.   Recently an algorithm was developed which combines the ideas behind LZ77 and
  364. LZ78 to produce a hybrid called LZFG.  LZFG uses the standard sliding window,
  365. but stores the data in a modified trie data structure and produces as output
  366. the position of the text in the trie.  Since LZFG only inserts complete
  367. *phrases* into the dictionary, it should run faster than other LZ77-based
  368. compressors.
  369.  
  370. All popular archivers (arj, lha, zip, zoo) are variations on the LZ77 theme.
  371.  
  372. ------------------------------------------------------------------------------
  373.  
  374. Subject: [71] Introduction to MPEG (long)
  375.  
  376.  
  377. Written by Mark Adler <madler@cco.caltech.edu>.
  378.  
  379. Q. What is MPEG?
  380. A. MPEG is a group of people that meet under ISO (the International
  381.    Standards Organization) to generate standards for digital video
  382.    (sequences of images in time) and audio compression.  In particular,
  383.    they define a compressed bit stream, which implicitly defines a
  384.    decompressor.  However, the compression algorithms are up to the
  385.    individual manufacturers, and that is where proprietary advantage
  386.    is obtained within the scope of a publicly available international
  387.    standard.  MPEG meets roughly four times a year for roughly a week
  388.    each time.  In between meetings, a great deal of work is done by
  389.    the members, so it doesn't all happen at the meetings.  The work
  390.    is organized and planned at the meetings.
  391.  
  392. Q. So what does MPEG stand for?
  393. A. Moving Pictures Experts Group.
  394.  
  395. Q. Does it have anything to do with JPEG?
  396. A. Well, it sounds the same, and they are part of the same subcommittee
  397.    of ISO along with JBIG and MHEG, and they usually meet at the same
  398.    place at the same time.  However, they are different sets of people
  399.    with few or no common individual members, and they have different
  400.    charters and requirements.  JPEG is for still image compression.
  401.  
  402. Q. Then what's JBIG and MHEG?
  403. A. Sorry I mentioned them. Ok, I'll simply say that JBIG is for binary
  404.    image compression (like faxes), and MHEG is for multi-media data
  405.    standards (like integrating stills, video, audio, text, etc.).
  406.    For an introduction to JBIG, see question 74 below.
  407.  
  408. Q. Ok, I'll stick to MPEG.  What has MPEG accomplished?
  409. A. So far (as of January 1992), they have completed the "Committee
  410.    Draft" of MPEG phase I, colloquially called MPEG I.  It defines
  411.    a bit stream for compressed video and audio optimized to fit into
  412.    a bandwidth (data rate) of 1.5 Mbits/s.  This rate is special
  413.    because it is the data rate of (uncompressed) audio CD's and DAT's.
  414.    The draft is in three parts, video, audio, and systems, where the
  415.    last part gives the integration of the audio and video streams
  416.    with the proper timestamping to allow synchronization of the two.
  417.    They have also gotten well into MPEG phase II, whose task is to
  418.    define a bitstream for video and audio coded at around 3 to 10
  419.    Mbits/s.
  420.  
  421. Q. So how does MPEG I work?
  422. A. First off, it starts with a relatively low resolution video
  423.    sequence (possibly decimated from the original) of about 352 by
  424.    240 frames by 30 frames/s (US--different numbers for Europe),
  425.    but original high (CD) quality audio.  The images are in color,
  426.    but converted to YUV space, and the two chrominance channels
  427.    (U and V) are decimated further to 176 by 120 pixels.  It turns
  428.    out that you can get away with a lot less resolution in those
  429.    channels and not notice it, at least in "natural" (not computer
  430.    generated) images.
  431.  
  432.    The basic scheme is to predict motion from frame to frame in the
  433.    temporal direction, and then to use DCT's (discrete cosine
  434.    transforms) to organize the redundancy in the spatial directions.
  435.    The DCT's are done on 8x8 blocks, and the motion prediction is
  436.    done in the luminance (Y) channel on 16x16 blocks.  In other words,
  437.    given the 16x16 block in the current frame that you are trying to
  438.    code, you look for a close match to that block in a previous or
  439.    future frame (there are backward prediction modes where later
  440.    frames are sent first to allow interpolating between frames).
  441.    The DCT coefficients (of either the actual data, or the difference
  442.    between this block and the close match) are "quantized", which
  443.    means that you divide them by some value to drop bits off the
  444.    bottom end.  Hopefully, many of the coefficients will then end up
  445.    being zero.  The quantization can change for every "macroblock"
  446.    (a macroblock is 16x16 of Y and the corresponding 8x8's in both
  447.    U and V).  The results of all of this, which include the DCT
  448.    coefficients, the motion vectors, and the quantization parameters
  449.    (and other stuff) is Huffman coded using fixed tables.  The DCT
  450.    coefficients have a special Huffman table that is "two-dimensional"
  451.    in that one code specifies a run-length of zeros and the non-zero
  452.    value that ended the run.  Also, the motion vectors and the DC
  453.    DCT components are DPCM (subtracted from the last one) coded.
  454.  
  455. Q. So is each frame predicted from the last frame?
  456. A. No.  The scheme is a little more complicated than that.  There are
  457.    three types of coded frames.  There are "I" or intra frames.  They
  458.    are simply a frame coded as a still image, not using any past
  459.    history.  You have to start somewhere.  Then there are "P" or
  460.    predicted frames.  They are predicted from the most recently
  461.    reconstructed I or P frame.  (I'm describing this from the point
  462.    of view of the decompressor.)  Each macroblock in a P frame can
  463.    either come with a vector and difference DCT coefficients for a
  464.    close match in the last I or P, or it can just be "intra" coded
  465.    (like in the I frames) if there was no good match.
  466.  
  467.    Lastly, there are "B" or bidirectional frames.  They are predicted
  468.    from the closest two I or P frames, one in the past and one in the
  469.    future.  You search for matching blocks in those frames, and try
  470.    three different things to see which works best.  (Now I have the
  471.    point of view of the compressor, just to confuse you.)  You try using
  472.    the forward vector, the backward vector, and you try averaging the
  473.    two blocks from the future and past frames, and subtracting that from
  474.    the block being coded.  If none of those work well, you can intra-
  475.    code the block.
  476.  
  477.    The sequence of decoded frames usually goes like:
  478.  
  479.    IBBPBBPBBPBBIBBPBBPB...
  480.  
  481.    Where there are 12 frames from I to I (for US and Japan anyway.)
  482.    This is based on a random access requirement that you need a
  483.    starting point at least once every 0.4 seconds or so.  The ratio
  484.    of P's to B's is based on experience.
  485.  
  486.    Of course, for the decoder to work, you have to send that first
  487.    P *before* the first two B's, so the compressed data stream ends
  488.    up looking like:
  489.  
  490.    0xx312645...
  491.  
  492.    where those are frame numbers.  xx might be nothing (if this is
  493.    the true starting point), or it might be the B's of frames -2 and
  494.    -1 if we're in the middle of the stream somewhere.
  495.  
  496.    You have to decode the I, then decode the P, keep both of those
  497.    in memory, and then decode the two B's.  You probably display the
  498.    I while you're decoding the P, and display the B's as you're
  499.    decoding them, and then display the P as you're decoding the next
  500.    P, and so on.
  501.  
  502. Q. You've got to be kidding.
  503. A. No, really!
  504.  
  505. Q. Hmm.  Where did they get 352x240?
  506. A. That derives from the CCIR-601 digital television standard which
  507.    is used by professional digital video equipment.  It is (in the US)
  508.    720 by 243 by 60 fields (not frames) per second, where the fields
  509.    are interlaced when displayed.  (It is important to note though
  510.    that fields are actually acquired and displayed a 60th of a second
  511.    apart.)  The chrominance channels are 360 by 243 by 60 fields a
  512.    second, again interlaced.  This degree of chrominance decimation
  513.    (2:1 in the horizontal direction) is called 4:2:2.  The source
  514.    input format for MPEG I, called SIF, is CCIR-601 decimated by 2:1
  515.    in the horizontal direction, 2:1 in the time direction, and an
  516.    additional 2:1 in the chrominance vertical direction.  And some
  517.    lines are cut off to make sure things divide by 8 or 16 where
  518.    needed.
  519.  
  520. Q. What if I'm in Europe?
  521. A. For 50 Hz display standards (PAL, SECAM) change the number of lines
  522.    in a field from 243 or 240 to 288, and change the display rate to
  523.    50 fields/s or 25 frames/s.  Similarly, change the 120 lines in
  524.    the decimated chrominance channels to 144 lines.  Since 288*50 is
  525.    exactly equal to 240*60, the two formats have the same source data
  526.    rate.
  527.  
  528. Q. You didn't mention anything about the audio compression.
  529. A. Oh, right.  Well, I don't know as much about the audio compression.
  530.    Basically they use very carefully developed psychoacoustic models
  531.    derived from experiments with the best obtainable listeners to
  532.    pick out pieces of the sound that you can't hear.  There are what
  533.    are called "masking" effects where, for example, a large component
  534.    at one frequency will prevent you from hearing lower energy parts
  535.    at nearby frequencies, where the relative energy vs. frequency
  536.    that is masked is described by some empirical curve.  There are
  537.    similar temporal masking effects, as well as some more complicated
  538.    interactions where a temporal effect can unmask a frequency, and
  539.    vice-versa.
  540.  
  541.    The sound is broken up into spectral chunks with a hybrid scheme
  542.    that combines sine transforms with subband transforms, and the
  543.    psychoacoustic model written in terms of those chunks.  Whatever
  544.    can be removed or reduced in precision is, and the remainder is
  545.    sent.  It's a little more complicated than that, since the bits
  546.    have to be allocated across the bands.  And, of course, what is
  547.    sent is entropy coded.
  548.  
  549. Q. So how much does it compress?
  550. A. As I mentioned before, audio CD data rates are about 1.5 Mbits/s.
  551.    You can compress the same stereo program down to 256 Kbits/s with
  552.    no loss in discernable quality.  (So they say.  For the most part
  553.    it's true, but every once in a while a weird thing might happen
  554.    that you'll notice.  However the effect is very small, and it takes
  555.    a listener trained to notice these particular types of effects.)
  556.    That's about 6:1 compression.  So, a CD MPEG I stream would have
  557.    about 1.25 MBits/s left for video.  The number I usually see though
  558.    is 1.15 MBits/s (maybe you need the rest for the system data
  559.    stream).  You can then calculate the video compression ratio from
  560.    the numbers here to be about 26:1.  If you step back and think
  561.    about that, it's little short of a miracle.  Of course, it's lossy
  562.    compression, but it can be pretty hard sometimes to see the loss,
  563.    if you're comparing the SIF original to the SIF decompressed.  There
  564.    is, however, a very noticeable loss if you're coming from CCIR-601
  565.    and have to decimate to SIF, but that's another matter.  I'm not
  566.    counting that in the 26:1.
  567.  
  568.    The standard also provides for other bit rates ranging from 32Kbits/s
  569.    for a single channel, up to 448 Kbits/s for stereo.
  570.  
  571. Q. What's phase II?
  572. A. As I said, there is a considerable loss of quality in going from
  573.    CCIR-601 to SIF resolution.  For entertainment video, it's simply
  574.    not acceptable.  You want to use more bits and code all or almost
  575.    all the CCIR-601 data.  From subjective testing at the Japan
  576.    meeting in November 1991, it seems that 4 MBits/s can give very
  577.    good quality compared to the original CCIR-601 material.  The
  578.    objective of phase II is to define a bit stream optimized for these
  579.    resolutions and bit rates.
  580.  
  581. Q. Why not just scale up what you're doing with MPEG I?
  582. A. The main difficulty is the interlacing.  The simplest way to extend
  583.    MPEG I to interlaced material is to put the fields together into
  584.    frames (720x486x30/s).  This results in bad motion artifacts that
  585.    stem from the fact that moving objects are in different places
  586.    in the two fields, and so don't line up in the frames.  Compressing
  587.    and decompressing without taking that into account somehow tends to
  588.    muddle the objects in the two different fields.
  589.  
  590.    The other thing you might try is to code the even and odd field
  591.    streams separately.  This avoids the motion artifacts, but as you
  592.    might imagine, doesn't get very good compression since you are not
  593.    using the redundancy between the even and odd fields where there
  594.    is not much motion (which is typically most of image).
  595.  
  596.    Or you can code it as a single stream of fields.  Or you can
  597.    interpolate lines.  Or, etc. etc.  There are many things you can
  598.    try, and the point of MPEG II is to figure out what works well.
  599.    MPEG II is not limited to consider only derivations of MPEG I.
  600.    There were several non-MPEG I-like schemes in the competition in
  601.    November, and some aspects of those algorithms may or may not
  602.    make it into the final standard for entertainment video compression.
  603.  
  604. Q. So what works?
  605. A. Basically, derivations of MPEG I worked quite well, with one that
  606.    used wavelet subband coding instead of DCT's that also worked very
  607.    well.  Also among the worked-very-well's was a scheme that did not
  608.    use B frames at all, just I and P's.  All of them, except maybe one,
  609.    did some sort of adaptive frame/field coding, where a decision is
  610.    made on a macroblock basis as to whether to code that one as one
  611.    frame macroblock or as two field macroblocks.  Some other aspects
  612.    are how to code I-frames--some suggest predicting the even field
  613.    from the odd field.  Or you can predict evens from evens and odds
  614.    or odds from evens and odds or any field from any other field, etc.
  615.  
  616. Q. So what works?
  617. A. Ok, we're not really sure what works best yet.  The next step is
  618.    to define a "test model" to start from, that incorporates most of
  619.    the salient features of the worked-very-well proposals in a
  620.    simple way.  Then experiments will be done on that test model,
  621.    making a mod at a time, and seeing what makes it better and what
  622.    makes it worse.  Example experiments are, B's or no B's, DCT vs.
  623.    wavelets, various field prediction modes, etc.  The requirements,
  624.    such as implementation cost, quality, random access, etc. will all
  625.    feed into this process as well.
  626.  
  627. Q. When will all this be finished?
  628. A. I don't know.  I'd have to hope in about a year or less.
  629.  
  630. Q. How do I join MPEG?
  631. A. You don't join MPEG.  You have to participate in ISO as part of a
  632.    national delegation.  How you get to be part of the national
  633.    delegation is up to each nation.  I only know the U.S., where you
  634.    have to attend the corresponding ANSI meetings to be able to
  635.    attend the ISO meetings.  Your company or institution has to be
  636.    willing to sink some bucks into travel since, naturally, these
  637.    meetings are held all over the world.  (For example, Paris,
  638.    Santa Clara, Kurihama Japan, Singapore, Haifa Israel, Rio de
  639.    Janeiro, London, etc.)
  640.  
  641. Q. Well, then how do I get the documents, like the MPEG I draft?
  642. A. MPEG is a draft ISO standard. It's exact name is ISO CD 11172.
  643.    The draft consists of three parts: System, Video, and Audio. The
  644.    System part (11172-1) deals with synchronization and multiplexing
  645.    of audio-visual information, while the Video (11172-2) and Audio
  646.    part (11172-3) address the video and the audio compression techniques
  647.    respectively.
  648.  
  649.    You may order it from your national standards body (e.g. ANSI in
  650.    the USA) or buy it from companies like
  651.      OMNICOM
  652.      phone +44 438 742424
  653.      FAX +44 438 740154
  654.  
  655. ------------------------------------------------------------------------------
  656.  
  657. Subject: [72] What is wavelet theory?
  658.  
  659.  
  660. Preprints and software are available by anonymous ftp from the
  661. Yale Mathematics Department computer ceres.math.yale.edu[130.132.23.22],
  662. in pub/wavelets and pub/software.
  663.  
  664. epic is a pyramid wavelet coder. (For source code, see item 15 in part one).
  665.  
  666. Bill Press of Harvard/CfA has made some things available for anonymous
  667. ftp on cfata4.harvard.edu [128.103.40.79] in directory /pub. There is
  668. a short TeX article on wavelet theory (wavelet.tex, to be included in
  669. a future edition of Numerical Recipes), some sample wavelet code
  670. (wavelet.f, in FORTRAN - sigh), and a beta version of an astronomical
  671. image compression program which he is currently developing (FITS
  672. format data files only, in fitspress08.tar.Z).
  673.  
  674. An experimental wavelet decomposition program is available
  675. in linc.cis.upenn.edu:/pub/grasp/wavelet.tar.Z.
  676.  
  677. A mailing list dedicated to research on wavelets has been set up at the
  678. University of South Carolina. To subscribe to this mailing list, send a
  679. message with "subscribe" as the subject to wavelet@math.scarolina.edu.
  680.  
  681.  
  682. A 5 minute course in wavelet transforms, by Richard Kirk <rak@crosfield.co.uk>:
  683.  
  684. Do you know what a Haar transform is? Its a transform to another orthonormal
  685. space (like the DFT), but the basis functions are a set of square wave bursts
  686. like this...
  687.  
  688.    +--+                         +------+
  689.    +  |  +------------------    +      |      +--------------
  690.       +--+                             +------+
  691.  
  692.          +--+                                 +------+
  693.    ------+  |  +------------    --------------+      |      +
  694.             +--+                                     +------+
  695.  
  696.                +--+             +-------------+
  697.    ------------+  |  +------    +             |             +
  698.                   +--+                        +-------------+
  699.  
  700.                      +--+       +---------------------------+
  701.    ------------------+  |  +    +                           +
  702.                         +--+
  703.  
  704. This is the set of functions for an 8-element 1-D Haar transform. You
  705. can probably see how to extend this to higher orders and higher dimensions
  706. yourself. This is dead easy to calculate, but it is not what is usually
  707. understood by a wavelet transform.
  708.  
  709. If you look at the eight Haar functions you see we have four functions
  710. that code the highest resolution detail, two functions that code the
  711. coarser detail, one function that codes the coarser detail still, and the 
  712. top function that codes the average value for the whole `image'.
  713.  
  714. Haar function can be used to code images instead of the DFT. With bilevel
  715. images (such as text) the result can look better, and it is quicker to code.
  716. Flattish regions, textures, and soft edges in scanned images get a nasty
  717. `blocking' feel to them. This is obvious on hardcopy, but can be disguised on
  718. color CRTs by the effects of the shadow mask. The DCT gives more consistent
  719. results.
  720.  
  721. This connects up with another bit of maths sometimes called Multispectral
  722. Image Analysis, sometimes called Image Pyramids.
  723.  
  724. Suppose you want to produce a discretely sampled image from a continuous 
  725. function. You would do this by effectively `scanning' the function using a
  726. sinc function [ sin(x)/x ] `aperture'. This was proved by Shannon in the 
  727. `forties. You can do the same thing starting with a high resolution
  728. discretely sampled image. You can then get a whole set of images showing 
  729. the edges at different resolutions by differencing the image at one
  730. resolution with another version at another resolution. If you have made this
  731. set of images properly they ought to all add together to give the original 
  732. image.
  733.  
  734. This is an expansion of data. Suppose you started off with a 1K*1K image.
  735. You now may have a 64*64 low resolution image plus difference images at 128*128
  736. 256*256, 512*512 and 1K*1K. 
  737.  
  738. Where has this extra data come from? If you look at the difference images you 
  739. will see there is obviously some redundancy as most of the values are near 
  740. zero. From the way we constructed the levels we know that locally the average
  741. must approach zero in all levels but the top. We could then construct a set of
  742. functions out of the sync functions at any level so that their total value 
  743. at all higher levels is zero. This gives us an orthonormal set of basis 
  744. functions for a transform. The transform resembles the Haar transform a bit,
  745. but has symmetric wave pulses that decay away continuously in either direction
  746. rather than square waves that cut off sharply. This transform is the
  747. wavelet transform ( got to the point at last!! ).
  748.  
  749. These wavelet functions have been likened to the edge detecting functions
  750. believed to be present in the human retina.
  751.  
  752.  
  753. Loren I. Petrich <lip@s1.gov> adds that order 2 or 3 Daubechies
  754. discrete wavelet transforms have a speed comparable to DCT's, and
  755. usually achieve compression a factor of 2 better for the same image
  756. quality than the JPEG 8*8 DCT. (See item 25 in part 1 of this FAQ for
  757. references on fast DCT algorithms.)
  758.  
  759. ------------------------------------------------------------------------------
  760.  
  761. Subject: [73] What is the theoretical compression limit?
  762.  
  763.  
  764. There is no compressor that is guaranteed to compress all possible input
  765. files. If it compresses some files, then it must enlarge some others.
  766. This can be proven by a simple counting argument (see question 9).
  767.  
  768. As an extreme example, the following algorithm achieves 100%
  769. compression for one special input file and enlarges all other files by
  770. only one bit:
  771.  
  772. - if the input data is <insert your favorite one here>, output an empty file.
  773. - otherwise output one bit (zero or one) followed by the input data.
  774.  
  775. The concept of theoretical compression limit is meaningful only
  776. if you have a model for your input data. See question 70 above
  777. for some examples of data models.
  778.  
  779. ------------------------------------------------------------------------------
  780.  
  781. Subject: [74] Introduction to JBIG
  782.  
  783.  
  784. A short introduction, written by Mark Adler <madler@cco.caltech.edu>:
  785.  
  786.   JBIG losslessly compresses binary (one-bit/pixel) images.  (The B stands
  787.   for bi-level.)  Basically it models the redundancy in the image as the
  788.   correlations of the pixel currently being coded with a set of nearby
  789.   pixels called the template.  An example template might be the two
  790.   pixels preceding this one on the same line, and the five pixels centered
  791.   above this pixel on the previous line.  Note that this choice only
  792.   involves pixels that have already been seen from a scanner.
  793.  
  794.   The current pixel is then arithmetically coded based on the eight-bit
  795.   (including the pixel being coded) state so formed.  So there are (in this
  796.   case) 256 contexts to be coded.  The arithmetic coder and probability
  797.   estimator for the contexts are actually IBM's (patented) Q-coder.  The
  798.   Q-coder uses low precision, rapidly adaptable (those two are related)
  799.   probability estimation combined with a multiply-less arithmetic coder.
  800.   The probability estimation is intimately tied to the interval calculations
  801.   necessary for the arithmetic coding.
  802.  
  803.   JBIG actually goes beyond this and has adaptive templates, and probably
  804.   some other bells and whistles I don't know about.  You can find a
  805.   description of the Q-coder as well as the ancestor of JBIG in the Nov 88
  806.   issue of the IBM Journal of Research and Development.  This is a very
  807.   complete and well written set of five articles that describe the Q-coder
  808.   and a bi-level image coder that uses the Q-coder.
  809.  
  810.   You can use JBIG on grey-scale or even color images by simply applying
  811.   the algorithm one bit-plane at a time.  You would want to recode the
  812.   grey or color levels first though, so that adjacent levels differ in
  813.   only one bit (called Gray-coding).  I hear that this works well up to
  814.   about six bits per pixel, beyond which JPEG's lossless mode works better.
  815.   You need to use the Q-coder with JPEG also to get this performance.
  816.  
  817.   Actually no lossless mode works well beyond six bits per pixel, since
  818.   those low bits tend to be noise, which doesn't compress at all.
  819.  
  820.   Anyway, the intent of JBIG is to replace the current, less effective
  821.   group 3 and 4 fax algorithms.
  822.  
  823.  
  824. Another introduction to JBIG, written by Hank van Bekkem <jbek@oce.nl>:
  825.  
  826.   The following description of the JBIG algorithm is derived from
  827.   experiences with a software implementation I wrote following the
  828.   specifications in the revision 4.1 draft of September 16, 1991. The
  829.   source will not be made available in the public domain, as parts of
  830.   JBIG are patented.
  831.  
  832.   JBIG (Joint Bi-level Image Experts Group) is an experts group of ISO,
  833.   IEC and CCITT (JTC1/SC2/WG9 and SGVIII). Its job is to define a
  834.   compression standard for lossless image coding ([1]). The main
  835.   characteristics of the proposed algorithm are:
  836.   - Compatible progressive/sequential coding. This means that a
  837.     progressively coded image can be decoded sequentially, and the
  838.     other way around.
  839.   - JBIG will be a lossless image compression standard: all bits in
  840.     your images before and after compression and decompression will be
  841.     exactly the same.
  842.  
  843.   In the rest of this text I will first describe the JBIG algorithm in
  844.   a short abstract of the draft. I will conclude by saying something
  845.   about the value of JBIG.
  846.  
  847.  
  848.   JBIG algorithm.
  849.   --------------
  850.  
  851.   JBIG parameter P specifies the number of bits per pixel in the image.
  852.   Its allowable range is 1 through 255, but starting at P=8 or so,
  853.   compression will be more efficient using other algorithms. On the
  854.   other hand, medical images such as chest X-rays are often stored with
  855.   12 bits per pixel, while no distorsion is allowed, so JBIG can
  856.   certainly be of use in this area. To limit the number of bit changes
  857.   between adjacent decimal values (e.g. 127 and 128), it is wise to use
  858.   Gray coding before compressing multi-level images with JBIG. JBIG
  859.   then compresses the image on a bitplane basis, so the rest of this
  860.   text assumes bi-level pixels.
  861.  
  862.   Progressive coding is a way to send an image gradually to a receiver
  863.   instead of all at once. During sending, more detail is sent, and the
  864.   receiver can build the image from low to high detail. JBIG uses
  865.   discrete steps of detail by successively doubling the resolution. The
  866.   sender computes a number of resolution layers D, and transmits these
  867.   starting at the lowest resolution Dl. Resolution reduction uses
  868.   pixels in the high resolution layer and some already computed low
  869.   resolution pixels as an index into a lookup table. The contents of
  870.   this table can be specified by the user.
  871.  
  872.   Compatibility between progressive and sequential coding is achieved
  873.   by dividing an image into stripes. Each stripe is a horizontal bar
  874.   with a user definable height. Each stripe is separately coded and
  875.   transmitted, and the user can define in which order stripes,
  876.   resolutions and bitplanes (if P>1) are intermixed in the coded data.
  877.   A progressive coded image can be decoded sequentially by decoding
  878.   each stripe, beginning by the one at the top of the image, to its
  879.   full resolution, and then proceeding to the next stripe. Progressive
  880.   decoding can be done by decoding only a specific resolution layer
  881.   from all stripes.
  882.  
  883.   After dividing an image into bitplanes, resolution layers and
  884.   stripes, eventually a number of small bi-level bitmaps are left to
  885.   compress. Compression is done using a Q-coder. Reference [2]
  886.   contains a full description, I will only outline the basic principles
  887.   here.
  888.  
  889.   The Q-coder codes bi-level pixels as symbols using the probability of
  890.   occurrence of these symbols in a certain context. JBIG defines two
  891.   kinds of context, one for the lowest resolution layer (the base
  892.   layer), and one for all other layers (differential layers).
  893.   Differential layer contexts contain pixels in the layer to be coded,
  894.   and in the corresponding lower resolution layer.
  895.  
  896.   For each combination of pixel values in a context, the probability
  897.   distribution of black and white pixels can be different. In an all
  898.   white context, the probability of coding a white pixel will be much
  899.   greater than that of coding a black pixel. The Q-coder assigns, just
  900.   like a Huffman coder, more bits to less probable symbols, and so
  901.   achieves compression. The Q-coder can, unlike a Huffmann coder,
  902.   assign one output codebit to more than one input symbol, and thus is
  903.   able to compress bi-level pixels without explicit clustering, as
  904.   would be necessary using a Huffman coder.
  905.  
  906.   Maximum compression will be achieved when all probabilities (one set
  907.   for each combination of pixel values in the context) follow the
  908.   probabilities of the pixels. The Q-coder therefore continuously
  909.   adapts these probabilities to the symbols it sees.
  910.  
  911.  
  912.   JBIG value.
  913.   ----------
  914.  
  915.   In my opinion, JBIG can be regarded as two combined devices:
  916.   - Providing the user the service of sending or storing multiple
  917.     representations of images at different resolutions without any
  918.     extra cost in storage. Differential layer contexts contain pixels
  919.     in two resolution layers, and so enable the Q-coder to effectively
  920.     code the difference in information between the two layers, instead
  921.     of the information contained in every layer. This means that,
  922.     within a margin of approximately 5%, the number of resolution
  923.     layers doesn't effect the compression ratio.
  924.   - Providing the user a very efficient compression algorithm, mainly
  925.     for use with bi-level images. Compared to CCITT Group 4, JBIG is
  926.     approximately 10% to 50% better on text and line art, and even
  927.     better on halftones. JBIG is however, just like Group 4, somewhat
  928.     sensitive to noise in images. This means that the compression ratio
  929.     decreases when the amount of noise in your images increases.
  930.  
  931.   An example of an application would be browsing through an image
  932.   database, e.g. an EDMS (engineering document management system).
  933.   Large A0 size drawings at 300 dpi or so would be stored using five
  934.   resolution layers. The lowest resolution layer would fit on a
  935.   computer screen. Base layer compressed data would be stored at the
  936.   beginning of the compressed file, thus making browsing through large
  937.   numbers of compressed drawings possible by reading and decompressing
  938.   just the first small part of all files. When the user stops browsing,
  939.   the system could automatically start decompressing all remaining
  940.   detail for printing at high resolution.
  941.  
  942.   [1] "Progressive Bi-level Image Compression, Revision 4.1", ISO/IEC
  943.       JTC1/SC2/WG9, CD 11544, September 16, 1991
  944.   [2] "An overview of the basic principles of the Q-coder adaptive
  945.       binary arithmetic coder", W.B. Pennebaker, J.L. Mitchell, G.G.
  946.       Langdon, R.B. Arps, IBM Journal of research and development,
  947.       Vol.32, No.6, November 1988, pp. 771-726 (See also the other
  948.       articles about the Q-coder in this issue)
  949.