home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / compression-faq / part2 < prev    next >
Internet Message Format  |  1999-09-06  |  108KB

  1. Path: senator-bedfellow.mit.edu!sipb-server-1.mit.edu!gatech!newsfeed.mathworks.com!oleane!teaser.fr!not-for-mail
  2. From: jloup@gzip.OmitThis.org (Jean-loup Gailly)
  3. Newsgroups: comp.compression,comp.compression.research,news.answers,comp.answers
  4. Subject: comp.compression Frequently Asked Questions (part 2/3)
  5. Supersedes: <compr2_09jan99@gzip_org>
  6. Followup-To: comp.compression
  7. Date: 5 Sep 1999 22:36:25 +0200
  8. Organization: none
  9. Lines: 2084
  10. Approved: news-answers-request@mit.edu
  11. Distribution: world
  12. Expires: 31 Oct 1999 16:17:20 GMT
  13. Message-ID: <compr2_05sep99@gzip_org>
  14. References: <compr1_05sep99@gzip_org>
  15. Reply-To: jloup@gzip.OmitThis.org
  16. NNTP-Posting-Host: dip208.teaser.fr
  17. X-Trace: feed.teaser.fr 936563540 7922 194.51.100.208 (5 Sep 1999 20:32:20 GMT)
  18. X-Complaints-To: usenet@feed.teaser.fr
  19. NNTP-Posting-Date: 5 Sep 1999 20:32:20 GMT
  20. Summary: *** READ THIS BEFORE POSTING ***
  21. Keywords: data compression, FAQ
  22. Xref: senator-bedfellow.mit.edu comp.compression:47322 comp.compression.research:3103 news.answers:165987 comp.answers:37555
  23.  
  24. Archive-name: compression-faq/part2
  25. Last-modified: Sep 5th, 1999
  26.  
  27. This file is part 2 of a set of Frequently Asked Questions for the
  28. groups comp.compression and comp.compression.research.
  29.  
  30. If you did not get part 1 or 3, you can get them at
  31. http://www.faqs.org/faqs/compression-faq/part1/preamble.html or
  32. or ftp://rtfm.mit.edu/pub/usenet/news.answers/compression-faq/
  33.  
  34. If you don't want to see this FAQ regularly, please add the subject line to
  35. your kill file. If you have corrections or suggestions for this FAQ, send them
  36. to Jean-loup Gailly <jloup at gzip.org>.  Thank you.
  37.  
  38. Contents
  39. ========
  40.  
  41. Part 2: (Long) introductions to data compression techniques
  42.  
  43. [70] Introduction to data compression (long)
  44.        Huffman and Related Compression Techniques
  45.        Arithmetic Coding
  46.        Substitutional Compressors
  47.           The LZ78 family of compressors
  48.           The LZ77 family of compressors
  49.  
  50. [71] Introduction to MPEG (long)
  51.        What is MPEG?
  52.        Does it have anything to do with JPEG?
  53.        Then what's JBIG and MHEG?
  54.        What has MPEG accomplished?
  55.        So how does MPEG I work?
  56.        What about the audio compression?
  57.        So how much does it compress?
  58.        What's phase II?
  59.        When will all this be finished?
  60.        How do I join MPEG?
  61.        How do I get the documents, like the MPEG I draft?
  62.  
  63. [72] What is wavelet theory?
  64. [73] What is the theoretical compression limit?
  65. [74] Introduction to JBIG
  66. [75] Introduction to JPEG
  67. [76] What is Vector Quantization?
  68. [77] Introduction to Fractal compression
  69. [78] The Burrows-Wheeler block sorting algorithm (long)
  70.  
  71. Part 3: (Long) list of image compression hardware
  72.  
  73. [85] Image compression hardware
  74. [99] Acknowledgments
  75.  
  76.  
  77. Search for "Subject: [#]" to get to question number # quickly. Some news
  78. readers can also take advantage of the message digest format used here.
  79.  
  80. ------------------------------------------------------------------------------
  81.  
  82. Subject: [70] Introduction to data compression (long)
  83.  
  84.  
  85. Written by Peter Gutmann <pgut1@cs.aukuni.ac.nz>.
  86.  
  87.  Huffman and Related Compression Techniques
  88.  ------------------------------------------
  89.  
  90.   *Huffman compression* is a statistical data compression technique which 
  91. gives a reduction in the average code length used to represent the symbols of 
  92. a alphabet.  The Huffman code is an example of a code which is optimal in the 
  93. case where all symbols probabilities are integral powers of 1/2.  A Huffman 
  94. code can be built in the following manner:
  95.  
  96.   (1) Rank all symbols in order of probability of occurrence.
  97.     
  98.   (2) Successively combine the two symbols of the lowest probability to form
  99.       a new composite symbol; eventually we will build a binary tree where
  100.       each node is the probability of all nodes beneath it.
  101.  
  102.   (3) Trace a path to each leaf, noticing the direction at each node.
  103.  
  104.   For a given frequency distribution, there are many possible Huffman codes,
  105. but the total compressed length will be the same. It is possible to
  106. define a 'canonical' Huffman tree, that is, pick one of these alternative
  107. trees. Such a canonical tree can then be represented very compactly, by
  108. transmitting only the bit length of each code. This technique is used
  109. in most archivers (pkzip, lha, zoo, arj, ...).
  110.  
  111.  
  112.   A technique related to Huffman coding is *Shannon-Fano coding*, which
  113. works as follows:
  114.  
  115.   (1) Divide the set of symbols into two equal or almost equal subsets
  116.       based on the probability of occurrence of characters in each
  117.       subset.  The first subset is assigned a binary zero, the second
  118.       a binary one.
  119.  
  120.   (2) Repeat step (1) until all subsets have a single element.
  121.  
  122. The algorithm used to create the Huffman codes is bottom-up, and the
  123. one for the Shannon-Fano codes is top-down. Huffman encoding always
  124. generates optimal codes, Shannon-Fano sometimes uses a few more bits.
  125.  
  126. [See also "Practical Huffman coding" http://www.compressconsult.com/huffman/ ]
  127.  
  128.  
  129.  Arithmetic Coding
  130.  -----------------
  131.  
  132.   It would appear that Huffman or Shannon-Fano coding is the perfect
  133. means of compressing data.  However, this is *not* the case.  As
  134. mentioned above, these coding methods are optimal when and only when
  135. the symbol probabilities are integral powers of 1/2, which is usually
  136. not the case.
  137.  
  138.   The technique of *arithmetic coding* does not have this restriction:
  139. It achieves the same effect as treating the message as one single unit
  140. (a technique which would, for Huffman coding, require enumeration of
  141. every single possible message), and thus attains the theoretical
  142. entropy bound to compression efficiency for any source.
  143.  
  144.   Arithmetic coding works by representing a number by an interval of real 
  145. numbers between 0 and 1.  As the message becomes longer, the interval needed 
  146. to represent it becomes smaller and smaller, and the number of bits needed to 
  147. specify that interval increases.  Successive symbols in the message reduce 
  148. this interval in accordance with the probability of that symbol. The more
  149. likely symbols reduce the range by less, and thus add fewer bits to the   
  150. message.
  151.  
  152.      1                                             Codewords
  153.     +-----------+-----------+-----------+           /-----\
  154.     |           |8/9 YY     |  Detail   |<- 31/32    .11111
  155.     |           +-----------+-----------+<- 15/16    .1111
  156.     |    Y      |           | too small |<- 14/16    .1110
  157.     |2/3        |    YX     | for text  |<- 6/8      .110
  158.     +-----------+-----------+-----------+
  159.     |           |           |16/27 XYY  |<- 10/16    .1010
  160.     |           |           +-----------+
  161.     |           |    XY     |           |
  162.     |           |           |   XYX     |<- 4/8      .100
  163.     |           |4/9        |           |
  164.     |           +-----------+-----------+
  165.     |           |           |           |
  166.     |    X      |           |   XXY     |<- 3/8      .011
  167.     |           |           |8/27       |
  168.     |           |           +-----------+
  169.     |           |    XX     |           |
  170.     |           |           |           |<- 1/4      .01
  171.     |           |           |   XXX     |
  172.     |           |           |           |
  173.     |0          |           |           |
  174.     +-----------+-----------+-----------+
  175.  
  176.   As an example of arithmetic coding, lets consider the example of two
  177. symbols X and Y, of probabilities 0.66 and 0.33. To encode this message, we
  178. examine the first symbol: If it is a X, we choose the lower partition; if
  179. it is a Y, we choose the upper partition.  Continuing in this manner for
  180. three symbols, we get the codewords shown to the right of the diagram above
  181. - they can be found by simply taking an appropriate location in the
  182. interval for that particular set of symbols and turning it into a binary
  183. fraction. In practice, it is also necessary to add a special end-of-data
  184. symbol, which is not represented in this simpe example.
  185.         
  186.   In this case the arithmetic code is not completely efficient, which is due 
  187. to the shortness of the message - with longer messages the coding efficiency 
  188. does indeed approach 100%.
  189.  
  190.   Now that we have an efficient encoding technique, what can we do with it? 
  191. What we need is a technique for building a model of the data which we can 
  192. then use with the encoder.  The simplest model is a fixed one, for example a 
  193. table of standard letter frequencies for English text which we can then use 
  194. to get letter probabilities.  An improvement on this technique is to use an 
  195. *adaptive model*, in other words a model which adjusts itself to the data 
  196. which is being compressed as the data is compressed.  We can convert the 
  197. fixed model into an adaptive one by adjusting the symbol frequencies after 
  198. each new symbol is encoded, allowing the model to track the data being 
  199. transmitted.  However, we can do much better than that.
  200.  
  201. Using the symbol probabilities by themselves is not a particularly good
  202. estimate of the true entropy of the data: We can take into account
  203. intersymbol probabilities as well.  The best compressors available today
  204. take this approach: DMC (Dynamic Markov Coding) starts with a zero-order
  205. Markov model and gradually extends this initial model as compression
  206. progresses; PPM (Prediction by Partial Matching) looks for a match of the
  207. text to be compressed in an order-n context.  If no match is found, it
  208. drops to an order n-1 context, until it reaches order 0.  Both these
  209. techniques thus obtain a much better model of the data to be compressed,
  210. which, combined with the use of arithmetic coding, results in superior
  211. compression performance.
  212.  
  213.   So if arithmetic coding-based compressors are so powerful, why are they not 
  214. used universally?  Apart from the fact that they are relatively new and 
  215. haven't come into general use too much yet, there is also one major concern:  
  216. The fact that they consume rather large amounts of computing resources, both 
  217. in terms of CPU power and memory.  The building of sophisticated models for 
  218. the compression can chew through a fair amount of memory (especially in the 
  219. case of DMC, where the model can grow without bounds); and the arithmetic 
  220. coding itself involves a fair amount of number crunching.
  221. There is however an alternative approach, a class of compressors generally 
  222. referred to as *substitutional* or *dictionary-based compressors*.
  223.  
  224.  Substitutional Compressors
  225.  --------------------------
  226.  
  227.   The basic idea behind a substitutional compressor is to replace an 
  228. occurrence of a particular phrase or group of bytes in a piece of data with a 
  229. reference to a previous occurrence of that phrase.  There are two main 
  230. classes of schemes, named after Jakob Ziv and Abraham Lempel, who first 
  231. proposed them in 1977 and 1978.
  232.  
  233. <The LZ78 family of compressors>
  234.  
  235.   LZ78-based schemes work by entering phrases into a *dictionary* and then, 
  236. when a repeat occurrence of that particular phrase is found, outputting the 
  237. dictionary index instead of the phrase.  There exist several compression 
  238. algorithms based on this principle, differing mainly in the manner in which 
  239. they manage the dictionary.  The most well-known scheme (in fact the most 
  240. well-known of all the Lempel-Ziv compressors, the one which is generally (and 
  241. mistakenly) referred to as "Lempel-Ziv Compression"), is Terry Welch's LZW 
  242. scheme, which he designed in 1984 for implementation in hardware for high- 
  243. performance disk controllers.
  244.  
  245. Input string: /WED/WE/WEE/WEB
  246.  
  247. Character input:    Code output:    New code value and associated string:
  248.     /W                  /                   256 = /W
  249.     E                   W                   257 = WE
  250.     D                   E                   258 = ED
  251.     /                   D                   259 = D/
  252.     WE                  256                 260 = /WE
  253.     /                   E                   261 = E/
  254.     WEE                 260                 262 = /WEE
  255.     /W                  261                 263 = E/W
  256.     EB                  257                 264 = WEB
  257.     <END>               B
  258.     
  259.   LZW starts with a 4K dictionary, of which entries 0-255 refer to individual 
  260. bytes, and entries 256-4095 refer to substrings.  Each time a new code is 
  261. generated it means a new string has been parsed.  New strings are generated 
  262. by appending the current character K to the end of an existing string w.  The 
  263. algorithm for LZW compression is as follows:
  264.  
  265.   set w = NIL
  266.   loop
  267.       read a character K
  268.       if wK exists in the dictionary
  269.           w = wK
  270.       else
  271.           output the code for w
  272.           add wK to the string table
  273.           w = K
  274.   endloop
  275.  
  276.   A sample run of LZW over a (highly redundant) input string can be seen in 
  277. the diagram above.  The strings are built up character-by-character starting 
  278. with a code value of 256.  LZW decompression takes the stream of codes and 
  279. uses it to exactly recreate the original input data.  Just like the 
  280. compression algorithm, the decompressor adds a new string to the dictionary 
  281. each time it reads in a new code.  All it needs to do in addition is to 
  282. translate each incoming code into a string and send it to the output.  A 
  283. sample run of the LZW decompressor is shown in below.
  284.  
  285. Input code: /WED<256>E<260><261><257>B
  286.  
  287. Input code:        Output string:     New code value and associated string:
  288.     /                  /            
  289.     W                  W                      256 = /W
  290.     E                  E                      257 = WE
  291.     D                  D                      258 = ED
  292.     256                /W                     259 = D/
  293.     E                  E                      260 = /WE
  294.     260                /WE                    261 = E/
  295.     261                E/                     262 = /WEE
  296.     257                WE                     263 = E/W
  297.     B                  B                      264 = WEB
  298.            
  299.   The most remarkable feature of this type of compression is that the entire 
  300. dictionary has been transmitted to the decoder without actually explicitly 
  301. transmitting the dictionary.  At the end of the run, the decoder will have a 
  302. dictionary identical to the one the encoder has, built up entirely as part of 
  303. the decoding process.
  304.     LZW is more commonly encountered today in a variant known as LZC, after 
  305. its use in the UNIX "compress" program.  In this variant, pointers do not 
  306. have a fixed length.  Rather, they start with a length of 9 bits, and then 
  307. slowly grow to their maximum possible length once all the pointers of a 
  308. particular size have been used up.  Furthermore, the dictionary is not frozen 
  309. once it is full as for LZW - the program continually monitors compression 
  310. performance, and once this starts decreasing the entire dictionary is 
  311. discarded and rebuilt from scratch.  More recent schemes use some sort of 
  312. least-recently-used algorithm to discard little-used phrases once the 
  313. dictionary becomes full rather than throwing away the entire dictionary.  
  314.  
  315. Finally, not all schemes build up the dictionary by adding a single new 
  316. character to the end of the current phrase. An alternative technique is to 
  317. concatenate the previous two phrases (LZMW), which results in a faster 
  318. buildup of longer phrases than the character-by-character buildup of the 
  319. other methods.  The disadvantage of this method is that a more sophisticated 
  320. data structure is needed to handle the dictionary.
  321.  
  322. [A good introduction to LZW, MW, AP and Y coding is given in the yabba
  323. package. For ftp information, see question 2 in part one, file type .Y]
  324.  
  325.  
  326. <The LZ77 family of compressors>
  327.  
  328.   LZ77-based schemes keep track of the last n bytes of data seen, and when a 
  329. phrase is encountered that has already been seen, they output a pair of 
  330. values corresponding to the position of the phrase in the previously-seen 
  331. buffer of data, and the length of the phrase.  In effect the compressor moves 
  332. a fixed-size *window* over the data (generally referred to as a *sliding 
  333. window*), with the position part of the (position, length) pair referring to 
  334. the position of the phrase within the window.  The most commonly used 
  335. algorithms are derived from the LZSS scheme described by James Storer and 
  336. Thomas Szymanski in 1982.  In this the compressor maintains a window of size 
  337. N bytes and a *lookahead buffer* the contents of which it tries to find a 
  338. match for in the window:
  339.  
  340.   while( lookAheadBuffer not empty )
  341.       {
  342.       get a pointer ( position, match ) to the longest match in the window
  343.           for the lookahead buffer;
  344.  
  345.       if( length > MINIMUM_MATCH_LENGTH )
  346.           {
  347.           output a ( position, length ) pair;
  348.           shift the window length characters along;
  349.           }
  350.       else
  351.           {
  352.           output the first character in the lookahead buffer;
  353.           shift the window 1 character along;
  354.           }
  355.       }
  356.         
  357.   Decompression is simple and fast:  Whenever a ( position, length ) pair is 
  358. encountered, go to that ( position ) in the window and copy ( length ) bytes 
  359. to the output.
  360.  
  361.   Sliding-window-based schemes can be simplified by numbering the input text
  362. characters mod N, in effect creating a circular buffer.  The sliding window
  363. approach automatically creates the LRU effect which must be done explicitly in
  364. LZ78 schemes.  Variants of this method apply additional compression to the
  365. output of the LZSS compressor, which include a simple variable-length code
  366. (LZB), dynamic Huffman coding (LZH), and Shannon-Fano coding (ZIP 1.x)), all
  367. of which result in a certain degree of improvement over the basic scheme,
  368. especially when the data are rather random and the LZSS compressor has little
  369. effect.
  370.   Recently an algorithm was developed which combines the ideas behind LZ77 and
  371. LZ78 to produce a hybrid called LZFG.  LZFG uses the standard sliding window,
  372. but stores the data in a modified trie data structure and produces as output
  373. the position of the text in the trie.  Since LZFG only inserts complete
  374. *phrases* into the dictionary, it should run faster than other LZ77-based
  375. compressors.
  376.  
  377. All popular archivers (arj, lha, zip, zoo) are variations on the LZ77 theme.
  378.  
  379.  
  380. [A tutorial on some compression algorithms is available at
  381. http://www.cs.sfu.ca/cs/CC/365/li/squeeze/ ]
  382.  
  383. ------------------------------------------------------------------------------
  384.  
  385. Subject: [71] Introduction to MPEG (long)
  386.  
  387.  
  388. For MPEG players, see item 15 in part 1 of the FAQ.  Frank Gadegast
  389. <phade@cs.tu-berlin.de> also posts a FAQ specialized in MPEG, available in
  390. ftp://ftp.cs.tu-berlin.de/pub/msdos/dos/graphics/ mpegfa*.zip and
  391. http://www.powerweb.de/mpeg/mpegfaq/
  392.  
  393. The site ftp://ftp.crs4.it/mpeg/ dedicated to the MPEG compression standard.
  394. Another MPEG FAQ is available in http://www.vol.it/MPEG/
  395.  
  396. See also http://www.mpeg.org and http://www-plateau.cs.berkeley.edu/mpeg
  397.  
  398. A description of MPEG can be found in: "MPEG: A Video Compression
  399. Standard for Multimedia Applications" Didier Le Gall, Communications
  400. of the ACM, April 1991, Vol 34. No.4, pp.46-58.
  401.  
  402. Several books on MPEG have been published, see the list in
  403. http://www.mpeg.org/MPEG/starting-points.html#books
  404.  
  405. MPEG-2 bitstreams are available on wuarchive.wustl.edu in directory
  406. /graphics/x3l3/pub/bitstreams. MPEG-2 Demultiplexer source code is
  407. in /graphics/x3l3/pub/bitstreams/systems/munsi_v13.tar.gz
  408.  
  409. Public C source encoder for all 3 layers for mpeg2 including mpeg1 is in
  410. ftp://ftp.tnt.uni-hannover.de/pub/MPEG/audio/mpeg2/public_software/
  411. technical_report/dist08.tar.gz
  412.  
  413.  
  414. Introduction to MPEG originally written by Mark Adler 
  415. <madler@cco.caltech.edu> around January 1992; modified and updated by 
  416. Harald Popp <layer3@iis.fhg.de> in March 94:
  417.  
  418. Q: What is MPEG, exactly?
  419.  
  420. A: MPEG is the "Moving Picture Experts Group", working under the 
  421.    joint direction of the International Standards Organization (ISO) 
  422.    and the International Electro-Technical Commission (IEC). This 
  423.    group works on standards for the coding of moving pictures and 
  424.    associated audio.
  425.  
  426. Q: What is the status of MPEG's work, then? What's about MPEG-1, -2, 
  427.    and so on?
  428.  
  429. A: MPEG approaches the growing need for multimedia standards step-by-
  430.    step. Today, three "phases" are defined:
  431.    
  432.    MPEG-1: "Coding of Moving Pictures and Associated Audio for 
  433.            Digital Storage Media at up to about 1.5 MBit/s"  
  434.  
  435.    Status: International Standard IS-11172, completed in 10.92
  436.    
  437.    MPEG-2: "Generic Coding of Moving Pictures and Associated Audio"
  438.    
  439.    Status: Comittee Draft CD 13818 as found in documents MPEG93 / 
  440.            N601, N602, N603 (11.93)   
  441.  
  442.    MPEG-3: no longer exists (has been merged into MPEG-2)
  443.    
  444.    MPEG-4: "Very Low Bitrate Audio-Visual Coding"
  445.    
  446.    Status: Call for Proposals 11.94, Working Draft in 11.96 
  447.  
  448. Q: MPEG-1 is ready-for-use. How does the standard look like?
  449.  
  450. A: MPEG-1 consists of 4 parts:
  451.  
  452.    IS 11172-1: System
  453.    describes synchronization and multiplexing of video and audio
  454.  
  455.    IS 11172-2: Video
  456.    describes compression of non-interlaced video signals
  457.    
  458.    IS 11172-3: Audio
  459.    describes compression of audio signals 
  460.    
  461.    CD 11172-4: Compliance Testing
  462.    describes procedures for determining the characteristics of coded 
  463.    bitstreams and the decoding porcess and for testing compliance 
  464.    with the requirements stated in the other parts
  465.  
  466. Q. Does MPEG have anything to do with JPEG? 
  467.  
  468. A. Well, it sounds the same, and they are part of the same 
  469.    subcommittee of ISO along with JBIG and MHEG, and they usually meet 
  470.    at the same place at the same time.  However, they are different 
  471.    sets of people with few or no common individual members, and they 
  472.    have different charters and requirements.  JPEG is for still image 
  473.    compression.
  474.  
  475. Q. Then what's JBIG and MHEG?
  476.  
  477. A. Sorry I mentioned them. Ok, I'll simply say that JBIG is for binary
  478.    image compression (like faxes), and MHEG is for multi-media data
  479.    standards (like integrating stills, video, audio, text, etc.).
  480.    For an introduction to JBIG, see question 74 below.
  481.  
  482. Q. So how does MPEG-1 work? Tell me about video coding!
  483.  
  484. A. First off, it starts with a relatively low resolution video
  485.    sequence (possibly decimated from the original) of about 352 by
  486.    240 frames by 30 frames/s (US--different numbers for Europe),
  487.    but original high (CD) quality audio.  The images are in color,
  488.    but converted to YUV space, and the two chrominance channels
  489.    (U and V) are decimated further to 176 by 120 pixels.  It turns
  490.    out that you can get away with a lot less resolution in those
  491.    channels and not notice it, at least in "natural" (not computer
  492.    generated) images.
  493.  
  494.    The basic scheme is to predict motion from frame to frame in the
  495.    temporal direction, and then to use DCT's (discrete cosine
  496.    transforms) to organize the redundancy in the spatial directions.
  497.    The DCT's are done on 8x8 blocks, and the motion prediction is
  498.    done in the luminance (Y) channel on 16x16 blocks.  In other words,
  499.    given the 16x16 block in the current frame that you are trying to
  500.    code, you look for a close match to that block in a previous or
  501.    future frame (there are backward prediction modes where later
  502.    frames are sent first to allow interpolating between frames).
  503.    The DCT coefficients (of either the actual data, or the difference
  504.    between this block and the close match) are "quantized", which
  505.    means that you divide them by some value to drop bits off the
  506.    bottom end.  Hopefully, many of the coefficients will then end up
  507.    being zero.  The quantization can change for every "macroblock"
  508.    (a macroblock is 16x16 of Y and the corresponding 8x8's in both
  509.    U and V).  The results of all of this, which include the DCT
  510.    coefficients, the motion vectors, and the quantization parameters
  511.    (and other stuff) is Huffman coded using fixed tables.  The DCT
  512.    coefficients have a special Huffman table that is "two-dimensional"
  513.    in that one code specifies a run-length of zeros and the non-zero
  514.    value that ended the run.  Also, the motion vectors and the DC
  515.    DCT components are DPCM (subtracted from the last one) coded.
  516.  
  517. Q. So is each frame predicted from the last frame?
  518.  
  519. A. No.  The scheme is a little more complicated than that.  There are
  520.    three types of coded frames.  There are "I" or intra frames.  They
  521.    are simply a frame coded as a still image, not using any past
  522.    history.  You have to start somewhere.  Then there are "P" or
  523.    predicted frames.  They are predicted from the most recently
  524.    reconstructed I or P frame.  (I'm describing this from the point
  525.    of view of the decompressor.)  Each macroblock in a P frame can
  526.    either come with a vector and difference DCT coefficients for a
  527.    close match in the last I or P, or it can just be "intra" coded
  528.    (like in the I frames) if there was no good match.
  529.  
  530.    Lastly, there are "B" or bidirectional frames.  They are predicted
  531.    from the closest two I or P frames, one in the past and one in the
  532.    future.  You search for matching blocks in those frames, and try
  533.    three different things to see which works best.  (Now I have the
  534.    point of view of the compressor, just to confuse you.)  You try 
  535.    using the forward vector, the backward vector, and you try 
  536.    averaging the two blocks from the future and past frames, and 
  537.    subtracting that from the block being coded.  If none of those work 
  538.    well, you can intracode the block.
  539.  
  540.    The sequence of decoded frames usually goes like:
  541.  
  542.    IBBPBBPBBPBBIBBPBBPB...
  543.  
  544.    Where there are 12 frames from I to I (for US and Japan anyway.)
  545.    This is based on a random access requirement that you need a
  546.    starting point at least once every 0.4 seconds or so.  The ratio
  547.    of P's to B's is based on experience.
  548.  
  549.    Of course, for the decoder to work, you have to send that first
  550.    P *before* the first two B's, so the compressed data stream ends
  551.    up looking like:
  552.  
  553.    0xx312645...
  554.  
  555.    where those are frame numbers.  xx might be nothing (if this is
  556.    the true starting point), or it might be the B's of frames -2 and
  557.    -1 if we're in the middle of the stream somewhere.
  558.  
  559.    You have to decode the I, then decode the P, keep both of those
  560.    in memory, and then decode the two B's.  You probably display the
  561.    I while you're decoding the P, and display the B's as you're
  562.    decoding them, and then display the P as you're decoding the next
  563.    P, and so on.
  564.  
  565. Q. You've got to be kidding.
  566.  
  567. A. No, really!
  568.  
  569. Q. Hmm.  Where did they get 352x240?
  570.  
  571. A. That derives from the CCIR-601 digital television standard which
  572.    is used by professional digital video equipment.  It is (in the US)
  573.    720 by 243 by 60 fields (not frames) per second, where the fields
  574.    are interlaced when displayed.  (It is important to note though
  575.    that fields are actually acquired and displayed a 60th of a second
  576.    apart.)  The chrominance channels are 360 by 243 by 60 fields a
  577.    second, again interlaced.  This degree of chrominance decimation
  578.    (2:1 in the horizontal direction) is called 4:2:2.  The source
  579.    input format for MPEG I, called SIF, is CCIR-601 decimated by 2:1
  580.    in the horizontal direction, 2:1 in the time direction, and an
  581.    additional 2:1 in the chrominance vertical direction.  And some
  582.    lines are cut off to make sure things divide by 8 or 16 where
  583.    needed.
  584.  
  585. Q. What if I'm in Europe?
  586.  
  587. A. For 50 Hz display standards (PAL, SECAM) change the number of lines
  588.    in a field from 243 or 240 to 288, and change the display rate to
  589.    50 fields/s or 25 frames/s.  Similarly, change the 120 lines in
  590.    the decimated chrominance channels to 144 lines.  Since 288*50 is
  591.    exactly equal to 240*60, the two formats have the same source data
  592.    rate.
  593.  
  594. Q. What will MPEG-2 do for video coding?
  595.  
  596. A. As I said, there is a considerable loss of quality in going from
  597.    CCIR-601 to SIF resolution.  For entertainment video, it's simply
  598.    not acceptable.  You want to use more bits and code all or almost
  599.    all the CCIR-601 data.  From subjective testing at the Japan
  600.    meeting in November 1991, it seems that 4 MBits/s can give very
  601.    good quality compared to the original CCIR-601 material.  The
  602.    objective of MPEG-2 is to define a bit stream optimized for 
  603.    these resolutions and bit rates.
  604.  
  605. Q. Why not just scale up what you're doing with MPEG-1?
  606.  
  607. A. The main difficulty is the interlacing.  The simplest way to extend
  608.    MPEG-1 to interlaced material is to put the fields together into
  609.    frames (720x486x30/s).  This results in bad motion artifacts that
  610.    stem from the fact that moving objects are in different places
  611.    in the two fields, and so don't line up in the frames.  Compressing
  612.    and decompressing without taking that into account somehow tends to
  613.    muddle the objects in the two different fields.
  614.  
  615.    The other thing you might try is to code the even and odd field
  616.    streams separately.  This avoids the motion artifacts, but as you
  617.    might imagine, doesn't get very good compression since you are not
  618.    using the redundancy between the even and odd fields where there
  619.    is not much motion (which is typically most of image).
  620.  
  621.    Or you can code it as a single stream of fields.  Or you can
  622.    interpolate lines.  Or, etc. etc.  There are many things you can
  623.    try, and the point of MPEG-2 is to figure out what works well.
  624.    MPEG-2 is not limited to consider only derivations of MPEG-1.
  625.    There were several non-MPEG-1-like schemes in the competition in
  626.    November, and some aspects of those algorithms may or may not
  627.    make it into the final standard for entertainment video 
  628.    compression.
  629.  
  630. Q. So what works?
  631.  
  632. A. Basically, derivations of MPEG-1 worked quite well, with one that
  633.    used wavelet subband coding instead of DCT's that also worked very
  634.    well.  Also among the worked-very-well's was a scheme that did not
  635.    use B frames at all, just I and P's.  All of them, except maybe 
  636.    one, did some sort of adaptive frame/field coding, where a decision 
  637.    is made on a macroblock basis as to whether to code that one as 
  638.    one frame macroblock or as two field macroblocks.  Some other 
  639.    aspects are how to code I-frames--some suggest predicting the even 
  640.    field from the odd field.  Or you can predict evens from evens and 
  641.    odds or odds from evens and odds or any field from any other field, 
  642.    etc.
  643.  
  644. Q. So what works?
  645.  
  646. A. Ok, we're not really sure what works best yet.  The next step is
  647.    to define a "test model" to start from, that incorporates most of
  648.    the salient features of the worked-very-well proposals in a
  649.    simple way.  Then experiments will be done on that test model,
  650.    making a mod at a time, and seeing what makes it better and what
  651.    makes it worse.  Example experiments are, B's or no B's, DCT vs.
  652.    wavelets, various field prediction modes, etc.  The requirements,
  653.    such as implementation cost, quality, random access, etc. will all
  654.    feed into this process as well.
  655.  
  656. Q. When will all this be finished?
  657.  
  658. A. I don't know.  I'd have to hope in about a year or less.
  659.  
  660. Q: Talking about MPEG audio coding, I heard a lot about "Layer 1, 2 
  661.    and 3". What does it mean, exactly?   
  662.  
  663. A: MPEG-1, IS 11172-3, describes the compression of audio signals 
  664.    using high performance perceptual coding schemes. It specifies a 
  665.    family of three audio coding schemes, simply called Layer-1,-2,-3, 
  666.    with increasing encoder complexity and performance (sound quality 
  667.    per bitrate). The three codecs are compatible in a hierarchical 
  668.    way, i.e. a Layer-N decoder is able to decode bitstream data 
  669.    encoded in Layer-N and all Layers below N (e.g., a Layer-3 
  670.    decoder may accept Layer-1,-2 and -3, whereas a Layer-2 decoder 
  671.    may accept only Layer-1 and -2.)
  672.  
  673. Q: So we have a family of three audio coding schemes. What does the 
  674.    MPEG standard define, exactly?
  675.    
  676. A: For each Layer, the standard specifies the bitstream format and 
  677.    the decoder. To allow for future improvements, it does *not* 
  678.    specify the encoder , but an informative chapter gives an example 
  679.    for an encoder for each Layer.    
  680.  
  681. Q: What have the three audio Layers in common?
  682.  
  683. A: All Layers use the same basic structure. The coding scheme can be  
  684.    described as "perceptual noise shaping" or "perceptual subband / 
  685.    transform coding". 
  686.  
  687.    The encoder analyzes the spectral components of the audio signal 
  688.    by calculating a filterbank or transform and applies a 
  689.    psychoacoustic model to estimate the just noticeable noise-
  690.    level. In its quantization and coding stage, the encoder tries 
  691.    to allocate the available number of data bits in a way to meet 
  692.    both the bitrate and masking requirements.
  693.  
  694.    The decoder is much less complex. Its only task is to synthesize 
  695.    an audio signal out of the coded spectral components.
  696.    
  697.    All Layers use the same analysis filterbank (polyphase with 32 
  698.    subbands). Layer-3 adds a MDCT transform to increase the frequency 
  699.    resolution.
  700.    
  701.    All Layers use the same "header information" in their bitstream, 
  702.    to support the hierarchical structure of the standard.
  703.    
  704.    All Layers use a bitstream structure that contains parts that are 
  705.    more sensitive to biterrors ("header", "bit allocation", 
  706.    "scalefactors", "side information") and parts that are less 
  707.    sensitive ("data of spectral components").  
  708.  
  709.    All Layers may use 32, 44.1 or 48 kHz sampling frequency.
  710.    
  711.    All Layers are allowed to work with similar bitrates:
  712.    Layer-1: from 32 kbps to 448 kbps
  713.    Layer-2: from 32 kbps to 384 kbps
  714.    Layer-3: from 32 kbps to 320 kbps
  715.  
  716. Q: What are the main differences between the three Layers, from a 
  717.    global view?
  718.  
  719. A: From Layer-1 to Layer-3,
  720.    complexity increases (mainly true for the encoder),
  721.    overall codec delay increases, and
  722.    performance increases (sound quality per bitrate).
  723.  
  724. Q: Which Layer should I use for my application?
  725.  
  726. A: Good Question. Of course, it depends on all your requirements. But 
  727.    as a first approach, you should consider the available bitrate of 
  728.    your application as the Layers have been designed to support 
  729.    certain areas of bitrates most efficiently, i.e. with a minimum 
  730.    drop of sound quality.
  731.  
  732.    Let us look a little closer at the strong domains of each Layer.
  733.     
  734.    Layer-1: Its ISO target bitrate is 192 kbps per audio channel.
  735.  
  736.    Layer-1 is a simplified version of Layer-2. It is most useful for 
  737.    bitrates around the "high" bitrates around or above 192 kbps. A 
  738.    version of Layer-1 is used as "PASC" with the DCC recorder.
  739.  
  740.    Layer-2: Its ISO target bitrate is 128 kbps per audio channel.
  741.    
  742.    Layer-2 is identical with MUSICAM. It has been designed as trade-
  743.    off between sound quality per bitrate and encoder complexity. It 
  744.    is most useful for bitrates around the "medium" bitrates of 128 or 
  745.    even 96 kbps per audio channel. The DAB (EU 147) proponents have 
  746.    decided to use Layer-2 in the future Digital Audio Broadcasting 
  747.    network.      
  748.  
  749.    Layer-3: Its ISO target bitrate is 64 kbps per audio channel.
  750.    
  751.    Layer-3 merges the best ideas of MUSICAM and ASPEC. It has been 
  752.    designed for best performance at "low" bitrates around 64 kbps or 
  753.    even below. The Layer-3 format specifies a set of advanced 
  754.    features that all address one goal: to preserve as much sound 
  755.    quality as possible even at rather low bitrates. Today, Layer-3 is 
  756.    already in use in various telecommunication networks (ISDN, 
  757.    satellite links, and so on) and speech announcement systems. 
  758.  
  759. Q: Tell me more about sound quality. How do you assess that?
  760.  
  761. A: Today, there is no alternative to expensive listening tests. 
  762.    During the ISO-MPEG-1 process, 3 international listening tests 
  763.    have been performed, with a lot of trained listeners, supervised 
  764.    by Swedish Radio. They took place in 7.90, 3.91 and 11.91. Another 
  765.    international listening test was performed by CCIR, now ITU-R, in 
  766.    92.      
  767.    
  768.    All these tests used the "triple stimulus, hidden reference" 
  769.    method and the CCIR impairment scale to assess the audio quality.
  770.    The listening sequence is "ABC", with A = original, BC = pair of 
  771.    original / coded signal with random sequence, and the listener has 
  772.    to evaluate both B and C with a number between 1.0 and 5.0. The 
  773.    meaning of these values is:
  774.    
  775.    5.0 = transparent (this should be the original signal)
  776.    4.0 = perceptible, but not annoying (first differences noticable)  
  777.    3.0 = slightly annoying   
  778.    2.0 = annoying
  779.    1.0 = very annoying
  780.  
  781.    With perceptual codecs (like MPEG audio), all traditional 
  782.    parameters (like SNR, THD+N, bandwidth) are especially useless. 
  783.    Fraunhofer-IIS works on objective quality assessment tools, like 
  784.    the NMR meter (Noise-to-Mask-Ratio), too. BTW: If you need more 
  785.    informations about NMR, please contact nmr@iis.fhg.de.
  786.  
  787. Q: Now that I know how to assess quality, come on, tell me the 
  788.    results of these tests.
  789.    
  790. A: Well, for low bitrates, the main result is that at 60 or 64 kbps 
  791.    per channel), Layer-2 scored always between 2.1 and 2.6, whereas 
  792.    Layer-3 scored between 3.6 and 3.8. This is a significant increase 
  793.    in sound quality, indeed! Furthermore, the selection process for 
  794.    critical sound material showed that it was rather difficult to 
  795.    find worst-case material for Layer-3 whereas it was not so hard to 
  796.    find such items for Layer-2.
  797.   
  798. Q: OK, a Layer-2 codec at low bitrates may sound poor today, but 
  799.    couldn't that be improved in the future? I guess you just told me 
  800.    before that the encoder is not fixed in the standard.
  801.    
  802. A: Good thinking! As the sound quality mainly depends on the encoder 
  803.    implementation, it is true that there is no such thing as a "Layer-
  804.    N"- quality. So we definitely only know the performance of the 
  805.    reference codecs during the international tests. Who knows what 
  806.    will happen in the future? What we do know now, is:
  807.    
  808.    Today, Layer-3 already provides a sound quality that comes very 
  809.    near to CD quality at 64 kbps per channel. Layer-2 is far away 
  810.    from that.
  811.    
  812.    Tomorrow, both Layers may improve. Layer-2 has been designed as a 
  813.    trade-off between quality and complexity, so the bitstream format 
  814.    allows only limited innovations. In contrast, even the current
  815.    reference Layer-3-codec exploits only a small part of the powerful 
  816.    mechanisms inside the Layer-3 bitstream format.  
  817.  
  818. Q: All in all, you sound as if anybody should use Layer-3 for low 
  819.    bitrates. Why on earth do some vendors still offer only Layer-2 
  820.    equipment for these applications?
  821.    
  822. A: Well, maybe because they started to design and develop their 
  823.    system rather early, e.g. in 1990. As Layer-2 is identical with 
  824.    MUSICAM, it has been available since summer of 90, at latest. In 
  825.    that year, Layer-3 development started and could be successfully 
  826.    finished in spring 92. So, for a certain time, vendors could only 
  827.    exploit the existing part of the new MPEG standard.   
  828.    
  829.    Now the situation has changed. All Layers are available, the 
  830.    standard is completed, and new systems need not limit themselves, 
  831.    but may capitalize on the full features of MPEG audio.
  832.  
  833. Q: How do I get the MPEG documents?
  834.  
  835. A: You may order it from your national standards body.
  836.  
  837.    E.g., in Germany, please contact:
  838.    DIN-Beuth Verlag, Auslandsnormen
  839.    Mrs. Niehoff, Burggrafenstr. 6, D-10772 Berlin, Germany
  840.    Phone: 030-2601-2757, Fax: 030-2601-1231
  841.  
  842.    E.g., in USA, you may order it from ANSI [phone (212) 642-4900] or 
  843.    buy it from companies like OMNICOM phone +44 438 742424
  844.                                       FAX   +44 438 740154
  845.  
  846. Q. How do I join MPEG?
  847.  
  848. A. You don't join MPEG.  You have to participate in ISO as part of a
  849.    national delegation.  How you get to be part of the national
  850.    delegation is up to each nation.  I only know the U.S., where you
  851.    have to attend the corresponding ANSI meetings to be able to
  852.    attend the ISO meetings.  Your company or institution has to be
  853.    willing to sink some bucks into travel since, naturally, these
  854.    meetings are held all over the world.  (For example, Paris,
  855.    Santa Clara, Kurihama Japan, Singapore, Haifa Israel, Rio de
  856.    Janeiro, London, etc.)
  857.  
  858. ------------------------------------------------------------------------------
  859.  
  860. Subject: [72] What is wavelet theory?
  861.  
  862.  
  863. Preprints and software are available by anonymous ftp from the
  864. Yale Mathematics Department computer ftp://ceres.math.yale.edu/pub/wavelets/
  865. and /pub/software/ .
  866.  
  867. For source code of several wavelet coders, see item 15 in part one of
  868. this FAQ.
  869.  
  870. A list of pointers, covering theory, papers, books, implementations,
  871. resources and more can be found at
  872. http://www.amara.com/current/wavelet.html#Wavelinks
  873.  
  874. Bill Press of Harvard/CfA has made some things available on
  875. ftp://cfata4.harvard.edu/pub/ There is a short TeX article on wavelet
  876. theory (wavelet.tex, to be included in a future edition of Numerical
  877. Recipes), some sample wavelet code (wavelet.f, in FORTRAN - sigh), and
  878. a beta version of an astronomical image compression program which he
  879. is currently developing (FITS format data files only, in
  880. fitspress08.tar.Z).
  881.  
  882. The Rice Wavelet Toolbox Release 2.0 is available in
  883. ftp://cml.rice.edu/pub/dsp/software/ and /pub/dsp/papers/ .  This is a
  884. collection of MATLAB of "mfiles" and "mex" files for twoband and
  885. M-band filter bank/wavelet analysis from the DSP group and
  886. Computational Mathematics Laboratory (CML) at Rice University,
  887. Houston, TX.  This release includes application code for Synthetic
  888. Aperture Radar despeckling and for deblocking of JPEG decompressed
  889. Images.  Contact: Ramesh Gopinath <ramesh@rice.edu>.
  890.  
  891. A wavelet transform coder construction kit is available at
  892. http://www.cs.dartmouth.edu/~gdavis/wavelet/wavelet.html
  893. Contact: Geoff Davis <gdavis@cs.dartmouth.edu>
  894.  
  895. A matlab toolbox for constructing multi-scale image representations, 
  896. including Laplacian pyramids, QMFs, wavelets, and steerable pyramids, 
  897. is available at ftp://ftp.cis.upenn.edu/pub/eero/matlabPyrTools.tar.gz
  898. Contact: Eero Simoncelli <eero.simoncelli@nyu.edu>.
  899.  
  900. A mailing list dedicated to research on wavelets has been set up at the
  901. University of South Carolina. To subscribe to this mailing list, send a
  902. message with "subscribe" as the subject to wavelet@math.sc.edu.
  903. For back issues and other information, check the Wavelet Digest home page
  904. at http://www.wavelet.org/
  905.  
  906. A tutorial by M. Hilton, B. Jawerth, and A. Sengupta, entitled
  907. "Compressing Still and Moving Images with Wavelets" is available in
  908. ftp://ftp.math.sc.edu/pub/wavelet/papers/varia/tutorial/ . The
  909. files are "tutorial.ps.Z" and "fig8.ps.Z".  fig8 is a comparison of
  910. JPEG and wavelet compressed images and could take several hours to
  911. print. The tutorial is also available at
  912. http://www.mathsoft.com/wavelets.html
  913.  
  914. A page on wavelet-based HARC-C compression technology is available at
  915. http://www.harc.edu/HARCC.html
  916.  
  917. Commercial wavelet image compression software:
  918.   http://www.aware.com
  919.   http://www.summus.com
  920.   http://www.infinop.com
  921.  
  922. Details of the wavelet transform can be found in
  923. ftp://ftp.isds.duke.edu/pub/brani/papers/wav4kidsA.ps.Z
  924. ftp://ftp.isds.duke.edu/pub/brani/papers/wav4kidsB.ps.Z
  925.  
  926.  
  927. A 5 minute course in wavelet transforms, by Richard Kirk <rak@crosfield.co.uk>:
  928.  
  929. Do you know what a Haar transform is? Its a transform to another orthonormal
  930. space (like the DFT), but the basis functions are a set of square wave bursts
  931. like this...
  932.  
  933.    +--+                         +------+
  934.    +  |  +------------------    +      |      +--------------
  935.       +--+                             +------+
  936.  
  937.          +--+                                 +------+
  938.    ------+  |  +------------    --------------+      |      +
  939.             +--+                                     +------+
  940.  
  941.                +--+             +-------------+
  942.    ------------+  |  +------    +             |             +
  943.                   +--+                        +-------------+
  944.  
  945.                      +--+       +---------------------------+
  946.    ------------------+  |  +    +                           +
  947.                         +--+
  948.  
  949. This is the set of functions for an 8-element 1-D Haar transform. You
  950. can probably see how to extend this to higher orders and higher dimensions
  951. yourself. This is dead easy to calculate, but it is not what is usually
  952. understood by a wavelet transform.
  953.  
  954. If you look at the eight Haar functions you see we have four functions
  955. that code the highest resolution detail, two functions that code the
  956. coarser detail, one function that codes the coarser detail still, and the 
  957. top function that codes the average value for the whole `image'.
  958.  
  959. Haar function can be used to code images instead of the DFT. With bilevel
  960. images (such as text) the result can look better, and it is quicker to code.
  961. Flattish regions, textures, and soft edges in scanned images get a nasty
  962. `blocking' feel to them. This is obvious on hardcopy, but can be disguised on
  963. color CRTs by the effects of the shadow mask. The DCT gives more consistent
  964. results.
  965.  
  966. This connects up with another bit of maths sometimes called Multispectral
  967. Image Analysis, sometimes called Image Pyramids.
  968.  
  969. Suppose you want to produce a discretely sampled image from a continuous 
  970. function. You would do this by effectively `scanning' the function using a
  971. sinc function [ sin(x)/x ] `aperture'. This was proved by Shannon in the 
  972. `forties. You can do the same thing starting with a high resolution
  973. discretely sampled image. You can then get a whole set of images showing 
  974. the edges at different resolutions by differencing the image at one
  975. resolution with another version at another resolution. If you have made this
  976. set of images properly they ought to all add together to give the original 
  977. image.
  978.  
  979. This is an expansion of data. Suppose you started off with a 1K*1K image.
  980. You now may have a 64*64 low resolution image plus difference images at 128*128
  981. 256*256, 512*512 and 1K*1K. 
  982.  
  983. Where has this extra data come from? If you look at the difference images you 
  984. will see there is obviously some redundancy as most of the values are near 
  985. zero. From the way we constructed the levels we know that locally the average
  986. must approach zero in all levels but the top. We could then construct a set of
  987. functions out of the sync functions at any level so that their total value 
  988. at all higher levels is zero. This gives us an orthonormal set of basis 
  989. functions for a transform. The transform resembles the Haar transform a bit,
  990. but has symmetric wave pulses that decay away continuously in either direction
  991. rather than square waves that cut off sharply. This transform is the
  992. wavelet transform ( got to the point at last!! ).
  993.  
  994. These wavelet functions have been likened to the edge detecting functions
  995. believed to be present in the human retina.
  996.  
  997.  
  998. Loren I. Petrich <lip@s1.gov> adds that order 2 or 3 Daubechies
  999. discrete wavelet transforms have a speed comparable to DCT's, and
  1000. usually achieve compression a factor of 2 better for the same image
  1001. quality than the JPEG 8*8 DCT. (See item 25 in part 1 of this FAQ for
  1002. references on fast DCT algorithms.)
  1003.  
  1004. ------------------------------------------------------------------------------
  1005.  
  1006. Subject: [73] What is the theoretical compression limit?
  1007.  
  1008.  
  1009. This question can be understood in two different ways:
  1010.  
  1011. (a) For a given compressor/decompressor, what is the best possible lossless
  1012.     compression for an arbitrary string (byte sequence) given as input?
  1013.  
  1014. (b) For a given string, what is the best possible lossless
  1015.     compressor/decompressor?
  1016.  
  1017. For case (a), the question is generally meaningless, because a specific
  1018. compressor may compress one very large input file down to a single bit, and
  1019. enlarge all other files by only one bit.  There is no lossless compressor that
  1020. is guaranteed to compress all possible input files. If it compresses some
  1021. files, then it must enlarge some others.  This can be proven by a simple
  1022. counting argument (see item 9).  In case (a), the size of the decompressor is
  1023. not taken into account for the determination of the compression ratio since the
  1024. decompressor is fixed and it may decompress an arbitrary number of files of
  1025. arbitrary length.
  1026.  
  1027. For case (b), it is of course necessary to take into account the size of the
  1028. decompressor. The problem may be restated as "What is the shortest program P
  1029. which, when executed, produces the string S?".  The size of this program
  1030. is known as the Kolmogorov complexity of the string S.  Some (actually most)
  1031. strings are not compressible at all, by any program: the smallest
  1032. representation of the string is the string itself.  On the other hand, the
  1033. output of a pseudo-random number generator can be extremely compressible, since
  1034. it is sufficient to know the parameters and seed of the generator to reproduce
  1035. an arbitrary long sequence.
  1036.  
  1037. References: "An Introduction to Kolmogorov Complexity and its Applications",
  1038.    Ming Li and Paul Vitanyi, 2nd edition, Springer-Verlag, ISBN 0-387-94868-6
  1039.    http://www.cwi.nl/~paulv/kolmogorov.html
  1040.  
  1041. If you don't want to read a whole book, I recommend the excellent lecture
  1042. "Randomness & Complexity in Pure Mathematics" by G. J. Chaitin:
  1043.   http://www.cs.auckland.ac.nz/CDMTCS/chaitin/ijbc.html
  1044. The decimal and binary expansions of Chaitin's number Omega are examples of
  1045. uncompressible strings. There are more papers on
  1046. http://www.cs.auckland.ac.nz/CDMTCS/chaitin/
  1047.  
  1048. ------------------------------------------------------------------------------
  1049.  
  1050. Subject: [74] Introduction to JBIG
  1051.  
  1052.  
  1053. JBIG software and the JBIG specification are available in
  1054. ftp://nic.funet.fi/pub/graphics/misc/test-images/jbig.tar.gz
  1055.  
  1056. The ISO JBIG committee's home page is http://www.jpeg.org/public/welcome.htm
  1057.  
  1058.  
  1059. A short introduction to JBIG, written by Mark Adler <madler@cco.caltech.edu>:
  1060.  
  1061.   JBIG losslessly compresses binary (one-bit/pixel) images.  (The B stands
  1062.   for bi-level.)  Basically it models the redundancy in the image as the
  1063.   correlations of the pixel currently being coded with a set of nearby
  1064.   pixels called the template.  An example template might be the two
  1065.   pixels preceding this one on the same line, and the five pixels centered
  1066.   above this pixel on the previous line.  Note that this choice only
  1067.   involves pixels that have already been seen from a scanner.
  1068.  
  1069.   The current pixel is then arithmetically coded based on the eight-bit
  1070.   (including the pixel being coded) state so formed.  So there are (in this
  1071.   case) 256 contexts to be coded.  The arithmetic coder and probability
  1072.   estimator for the contexts are actually IBM's (patented) Q-coder.  The
  1073.   Q-coder uses low precision, rapidly adaptable (those two are related)
  1074.   probability estimation combined with a multiply-less arithmetic coder.
  1075.   The probability estimation is intimately tied to the interval calculations
  1076.   necessary for the arithmetic coding.
  1077.  
  1078.   JBIG actually goes beyond this and has adaptive templates, and probably
  1079.   some other bells and whistles I don't know about.  You can find a
  1080.   description of the Q-coder as well as the ancestor of JBIG in the Nov 88
  1081.   issue of the IBM Journal of Research and Development.  This is a very
  1082.   complete and well written set of five articles that describe the Q-coder
  1083.   and a bi-level image coder that uses the Q-coder.
  1084.  
  1085.   You can use JBIG on grey-scale or even color images by simply applying
  1086.   the algorithm one bit-plane at a time.  You would want to recode the
  1087.   grey or color levels first though, so that adjacent levels differ in
  1088.   only one bit (called Gray-coding).  I hear that this works well up to
  1089.   about six bits per pixel, beyond which JPEG's lossless mode works better.
  1090.   You need to use the Q-coder with JPEG also to get this performance.
  1091.  
  1092.   Actually no lossless mode works well beyond six bits per pixel, since
  1093.   those low bits tend to be noise, which doesn't compress at all.
  1094.  
  1095.   Anyway, the intent of JBIG is to replace the current, less effective
  1096.   group 3 and 4 fax algorithms.
  1097.  
  1098.  
  1099. Another introduction to JBIG, written by Hank van Bekkem <jbek@oce.nl>:
  1100.  
  1101.   The following description of the JBIG algorithm is derived from
  1102.   experiences with a software implementation I wrote following the
  1103.   specifications in the revision 4.1 draft of September 16, 1991. The
  1104.   source will not be made available in the public domain, as parts of
  1105.   JBIG are patented.
  1106.  
  1107.   JBIG (Joint Bi-level Image Experts Group) is an experts group of ISO,
  1108.   IEC and CCITT (JTC1/SC2/WG9 and SGVIII). Its job is to define a
  1109.   compression standard for lossless image coding ([1]). The main
  1110.   characteristics of the proposed algorithm are:
  1111.   - Compatible progressive/sequential coding. This means that a
  1112.     progressively coded image can be decoded sequentially, and the
  1113.     other way around.
  1114.   - JBIG will be a lossless image compression standard: all bits in
  1115.     your images before and after compression and decompression will be
  1116.     exactly the same.
  1117.  
  1118.   In the rest of this text I will first describe the JBIG algorithm in
  1119.   a short abstract of the draft. I will conclude by saying something
  1120.   about the value of JBIG.
  1121.  
  1122.  
  1123.   JBIG algorithm.
  1124.   --------------
  1125.  
  1126.   JBIG parameter P specifies the number of bits per pixel in the image.
  1127.   Its allowable range is 1 through 255, but starting at P=8 or so,
  1128.   compression will be more efficient using other algorithms. On the
  1129.   other hand, medical images such as chest X-rays are often stored with
  1130.   12 bits per pixel, while no distorsion is allowed, so JBIG can
  1131.   certainly be of use in this area. To limit the number of bit changes
  1132.   between adjacent decimal values (e.g. 127 and 128), it is wise to use
  1133.   Gray coding before compressing multi-level images with JBIG. JBIG
  1134.   then compresses the image on a bitplane basis, so the rest of this
  1135.   text assumes bi-level pixels.
  1136.  
  1137.   Progressive coding is a way to send an image gradually to a receiver
  1138.   instead of all at once. During sending, more detail is sent, and the
  1139.   receiver can build the image from low to high detail. JBIG uses
  1140.   discrete steps of detail by successively doubling the resolution. The
  1141.   sender computes a number of resolution layers D, and transmits these
  1142.   starting at the lowest resolution Dl. Resolution reduction uses
  1143.   pixels in the high resolution layer and some already computed low
  1144.   resolution pixels as an index into a lookup table. The contents of
  1145.   this table can be specified by the user.
  1146.  
  1147.   Compatibility between progressive and sequential coding is achieved
  1148.   by dividing an image into stripes. Each stripe is a horizontal bar
  1149.   with a user definable height. Each stripe is separately coded and
  1150.   transmitted, and the user can define in which order stripes,
  1151.   resolutions and bitplanes (if P>1) are intermixed in the coded data.
  1152.   A progressive coded image can be decoded sequentially by decoding
  1153.   each stripe, beginning by the one at the top of the image, to its
  1154.   full resolution, and then proceeding to the next stripe. Progressive
  1155.   decoding can be done by decoding only a specific resolution layer
  1156.   from all stripes.
  1157.  
  1158.   After dividing an image into bitplanes, resolution layers and
  1159.   stripes, eventually a number of small bi-level bitmaps are left to
  1160.   compress. Compression is done using a Q-coder. Reference [2]
  1161.   contains a full description, I will only outline the basic principles
  1162.   here.
  1163.  
  1164.   The Q-coder codes bi-level pixels as symbols using the probability of
  1165.   occurrence of these symbols in a certain context. JBIG defines two
  1166.   kinds of context, one for the lowest resolution layer (the base
  1167.   layer), and one for all other layers (differential layers).
  1168.   Differential layer contexts contain pixels in the layer to be coded,
  1169.   and in the corresponding lower resolution layer.
  1170.  
  1171.   For each combination of pixel values in a context, the probability
  1172.   distribution of black and white pixels can be different. In an all
  1173.   white context, the probability of coding a white pixel will be much
  1174.   greater than that of coding a black pixel. The Q-coder assigns, just
  1175.   like a Huffman coder, more bits to less probable symbols, and so
  1176.   achieves compression. The Q-coder can, unlike a Huffmann coder,
  1177.   assign one output codebit to more than one input symbol, and thus is
  1178.   able to compress bi-level pixels without explicit clustering, as
  1179.   would be necessary using a Huffman coder.
  1180.  
  1181.   Maximum compression will be achieved when all probabilities (one set
  1182.   for each combination of pixel values in the context) follow the
  1183.   probabilities of the pixels. The Q-coder therefore continuously
  1184.   adapts these probabilities to the symbols it sees.
  1185.  
  1186.  
  1187.   JBIG value.
  1188.   ----------
  1189.  
  1190.   In my opinion, JBIG can be regarded as two combined devices:
  1191.   - Providing the user the service of sending or storing multiple
  1192.     representations of images at different resolutions without any
  1193.     extra cost in storage. Differential layer contexts contain pixels
  1194.     in two resolution layers, and so enable the Q-coder to effectively
  1195.     code the difference in information between the two layers, instead
  1196.     of the information contained in every layer. This means that,
  1197.     within a margin of approximately 5%, the number of resolution
  1198.     layers doesn't effect the compression ratio.
  1199.   - Providing the user a very efficient compression algorithm, mainly
  1200.     for use with bi-level images. Compared to CCITT Group 4, JBIG is
  1201.     approximately 10% to 50% better on text and line art, and even
  1202.     better on halftones. JBIG is however, just like Group 4, somewhat
  1203.     sensitive to noise in images. This means that the compression ratio
  1204.     decreases when the amount of noise in your images increases.
  1205.  
  1206.   An example of an application would be browsing through an image
  1207.   database, e.g. an EDMS (engineering document management system).
  1208.   Large A0 size drawings at 300 dpi or so would be stored using five
  1209.   resolution layers. The lowest resolution layer would fit on a
  1210.   computer screen. Base layer compressed data would be stored at the
  1211.   beginning of the compressed file, thus making browsing through large
  1212.   numbers of compressed drawings possible by reading and decompressing
  1213.   just the first small part of all files. When the user stops browsing,
  1214.   the system could automatically start decompressing all remaining
  1215.   detail for printing at high resolution.
  1216.  
  1217.   [1] "Progressive Bi-level Image Compression, Revision 4.1", ISO/IEC
  1218.       JTC1/SC2/WG9, CD 11544, September 16, 1991
  1219.   [2] "An overview of the basic principles of the Q-coder adaptive
  1220.       binary arithmetic coder", W.B. Pennebaker, J.L. Mitchell, G.G.
  1221.       Langdon, R.B. Arps, IBM Journal of research and development,
  1222.       Vol.32, No.6, November 1988, pp. 771-726 (See also the other
  1223.       articles about the Q-coder in this issue)
  1224.  
  1225. ------------------------------------------------------------------------------
  1226.  
  1227. Subject: [75] Introduction to JPEG
  1228.  
  1229. Here is a brief overview of the inner workings of JPEG, plus some references
  1230. for more detailed information, written by Tom Lane <tgl@sss.pgh.pa.us>.
  1231. Please read item 19 in part 1 first.
  1232.  
  1233. JPEG works on either full-color or gray-scale images; it does not handle
  1234. bilevel (black and white) images, at least not well.  It doesn't handle
  1235. colormapped images either; you have to pre-expand those into an unmapped
  1236. full-color representation.  JPEG works best on "continuous tone" images.
  1237. Images with many sudden jumps in color values will not compress well.
  1238.  
  1239. There are a lot of parameters to the JPEG compression process.  By adjusting
  1240. the parameters, you can trade off compressed image size against reconstructed
  1241. image quality over a *very* wide range.  You can get image quality ranging
  1242. from op-art (at 100x smaller than the original 24-bit image) to quite
  1243. indistinguishable from the source (at about 3x smaller).  Usually the
  1244. threshold of visible difference from the source image is somewhere around 10x
  1245. to 20x smaller than the original, ie, 1 to 2 bits per pixel for color images.
  1246. Grayscale images do not compress as much.  In fact, for comparable visual
  1247. quality, a grayscale image needs perhaps 25% less space than a color image;
  1248. certainly not the 66% less that you might naively expect.
  1249.  
  1250. JPEG defines a "baseline" lossy algorithm, plus optional extensions for
  1251. progressive and hierarchical coding.  There is also a separate lossless
  1252. compression mode; this typically gives about 2:1 compression, ie, about 12
  1253. bits per color pixel.  Most currently available JPEG hardware and software
  1254. handles only the baseline mode.
  1255.  
  1256.  
  1257. Here's the outline of the baseline compression algorithm:
  1258.  
  1259. 1. Transform the image into a suitable color space.  This is a no-op for
  1260. grayscale, but for color images you generally want to transform RGB into a
  1261. luminance/chrominance color space (YCbCr, YUV, etc).  The luminance component
  1262. is grayscale and the other two axes are color information.  The reason for
  1263. doing this is that you can afford to lose a lot more information in the
  1264. chrominance components than you can in the luminance component: the human eye
  1265. is not as sensitive to high-frequency chroma info as it is to high-frequency
  1266. luminance.  (See any TV system for precedents.)  You don't have to change the
  1267. color space if you don't want to, since the remainder of the algorithm works
  1268. on each color component independently, and doesn't care just what the data
  1269. is.  However, compression will be less since you will have to code all the
  1270. components at luminance quality.  Note that colorspace transformation is
  1271. slightly lossy due to roundoff error, but the amount of error is much smaller
  1272. than what we typically introduce later on.
  1273.  
  1274. 2. (Optional) Downsample each component by averaging together groups of
  1275. pixels.  The luminance component is left at full resolution, while the chroma
  1276. components are often reduced 2:1 horizontally and either 2:1 or 1:1 (no
  1277. change) vertically.  In JPEG-speak these alternatives are usually called 2h2v
  1278. and 2h1v sampling, but you may also see the terms "411" and "422" sampling.
  1279. This step immediately reduces the data volume by one-half or one-third.
  1280. In numerical terms it is highly lossy, but for most images it has almost no
  1281. impact on perceived quality, because of the eye's poorer resolution for chroma
  1282. info.  Note that downsampling is not applicable to grayscale data; this is one
  1283. reason color images are more compressible than grayscale.
  1284.  
  1285. 3. Group the pixel values for each component into 8x8 blocks.  Transform each
  1286. 8x8 block through a discrete cosine transform (DCT).  The DCT is a relative of
  1287. the Fourier transform and likewise gives a frequency map, with 8x8 components.
  1288. Thus you now have numbers representing the average value in each block and
  1289. successively higher-frequency changes within the block.  The motivation for
  1290. doing this is that you can now throw away high-frequency information without
  1291. affecting low-frequency information.  (The DCT transform itself is reversible
  1292. except for roundoff error.)  See question 25 for fast DCT algorithms.
  1293.  
  1294. 4. In each block, divide each of the 64 frequency components by a separate
  1295. "quantization coefficient", and round the results to integers.  This is the
  1296. fundamental information-losing step.  The larger the quantization
  1297. coefficients, the more data is discarded.  Note that even the minimum possible
  1298. quantization coefficient, 1, loses some info, because the exact DCT outputs
  1299. are typically not integers.  Higher frequencies are always quantized less
  1300. accurately (given larger coefficients) than lower, since they are less visible
  1301. to the eye.  Also, the luminance data is typically quantized more accurately
  1302. than the chroma data, by using separate 64-element quantization tables.
  1303. Tuning the quantization tables for best results is something of a black art,
  1304. and is an active research area.  Most existing encoders use simple linear
  1305. scaling of the example tables given in the JPEG standard, using a single
  1306. user-specified "quality" setting to determine the scaling multiplier.  This
  1307. works fairly well for midrange qualities (not too far from the sample tables
  1308. themselves) but is quite nonoptimal at very high or low quality settings.
  1309.  
  1310. 5. Encode the reduced coefficients using either Huffman or arithmetic coding.
  1311. (Strictly speaking, baseline JPEG only allows Huffman coding; arithmetic
  1312. coding is an optional extension.)   Notice that this step is lossless, so it
  1313. doesn't affect image quality.  The arithmetic coding option uses Q-coding;
  1314. it is identical to the coder used in JBIG (see question 74).  Be aware that
  1315. Q-coding is patented.  Most existing implementations support only the Huffman
  1316. mode, so as to avoid license fees.  The arithmetic mode offers maybe 5 or 10%
  1317. better compression, which isn't enough to justify paying fees.
  1318.  
  1319. 6. Tack on appropriate headers, etc, and output the result.  In a normal
  1320. "interchange" JPEG file, all of the compression parameters are included
  1321. in the headers so that the decompressor can reverse the process.  These
  1322. parameters include the quantization tables and the Huffman coding tables.
  1323. For specialized applications, the spec permits those tables to be omitted
  1324. from the file; this saves several hundred bytes of overhead, but it means
  1325. that the decompressor must know a-priori what tables the compressor used.
  1326. Omitting the tables is safe only in closed systems.
  1327.  
  1328.  
  1329. The decompression algorithm reverses this process.  The decompressor
  1330. multiplies the reduced coefficients by the quantization table entries to
  1331. produce approximate DCT coefficients.  Since these are only approximate,
  1332. the reconstructed pixel values are also approximate, but if the design
  1333. has done what it's supposed to do, the errors won't be highly visible.
  1334. A high-quality decompressor will typically add some smoothing steps to
  1335. reduce pixel-to-pixel discontinuities.
  1336.  
  1337. The JPEG standard does not specify the exact behavior of compressors and
  1338. decompressors, so there's some room for creative implementation.  In
  1339. particular, implementations can trade off speed against image quality by
  1340. choosing more accurate or faster-but-less-accurate approximations to the
  1341. DCT.  Similar tradeoffs exist for the downsampling/upsampling and colorspace
  1342. conversion steps.  (The spec does include some minimum accuracy requirements
  1343. for the DCT step, but these are widely ignored, and are not too meaningful
  1344. anyway in the absence of accuracy requirements for the other lossy steps.)
  1345.  
  1346.  
  1347. Extensions:
  1348.  
  1349. The progressive mode is intended to support real-time transmission of images.
  1350. It allows the DCT coefficients to be sent piecemeal in multiple "scans" of
  1351. the image.  With each scan, the decoder can produce a higher-quality
  1352. rendition of the image.  Thus a low-quality preview can be sent very quickly,
  1353. then refined as time allows.  The total space needed is roughly the same as
  1354. for a baseline JPEG image of the same final quality.  (In fact, it can be
  1355. somewhat *less* if a custom Huffman table is used for each scan, because the
  1356. Huffman codes can be optimized over a smaller, more uniform population of
  1357. data than appears in a baseline image's single scan.)  The decoder must do
  1358. essentially a full JPEG decode cycle for each scan: inverse DCT, upsample,
  1359. and color conversion must all be done again, not to mention any color
  1360. quantization for 8-bit displays.  So this scheme is useful only with fast
  1361. decoders or slow transmission lines.  Up until 1995, progressive JPEG was a
  1362. rare bird, but its use is now spreading as software decoders have become fast
  1363. enough to make it useful with modem-speed data transmission.
  1364.  
  1365. The hierarchical mode represents an image at multiple resolutions.  For
  1366. example, one could provide 512x512, 1024x1024, and 2048x2048 versions of the
  1367. image.  The higher-resolution images are coded as differences from the next
  1368. smaller image, and thus require many fewer bits than they would if stored
  1369. independently.  (However, the total number of bits will be greater than that
  1370. needed to store just the highest-resolution frame in baseline form.)
  1371. The individual frames in a hierarchical sequence can be coded progressively
  1372. if desired.  Hierarchical mode is not widely supported at present.
  1373.  
  1374. Part 3 of the JPEG standard, approved at the end of 1995, introduces several
  1375. new extensions.  The one most likely to become popular is variable
  1376. quantization, which allows the quantization table to be scaled to different
  1377. levels in different parts of the image.  In this way the "more critical"
  1378. parts of the image can be coded at higher quality than the "less critical"
  1379. parts.  A signaling code can be inserted at any DCT block boundary to set a
  1380. new scaling factor.
  1381.  
  1382. Another Part 3 extension is selective refinement.  This feature permits a
  1383. scan in a progressive sequence, or a refinement frame of a hierarchical
  1384. sequence, to cover only part of the total image area.  This is an
  1385. alternative way of solving the variable-quality problem.  My (tgl's) guess
  1386. is that this will not get widely implemented, with variable quantization
  1387. proving a more popular approach, but I've been wrong before.
  1388.  
  1389. The third major extension added by Part 3 is a "tiling" concept that allows
  1390. an image to be built up as a composite of JPEG frames, which may have
  1391. different sizes, resolutions, quality settings, even colorspaces.  (For
  1392. example, a color image that occupies a small part of a mostly-grayscale page
  1393. could be represented as a separate frame, without having to store the whole
  1394. page in color.)  Again, there's some overlap in functionality with variable
  1395. quantization and selective refinement.  The general case of arbitrary tiles
  1396. is rather complex and is unlikely to be widely implemented.  In the simplest
  1397. case all the tiles are the same size and use similar quality settings.
  1398. This case may become popular even if the general tiling mechanism doesn't,
  1399. because it surmounts the 64K-pixel-on-a-side image size limitation that was
  1400. (not very foresightedly) built into the basic JPEG standard.  The individual
  1401. frames are still restricted to 64K for compatibility reasons, but the total
  1402. size of a tiled JPEG image can be up to 2^32 pixels on a side.
  1403.  
  1404. Lossless JPEG:
  1405.  
  1406. The separate lossless mode does not use DCT, since roundoff errors prevent a
  1407. DCT calculation from being lossless.  For the same reason, one would not
  1408. normally use colorspace conversion or downsampling, although these are
  1409. permitted by the standard.  The lossless mode simply codes the difference
  1410. between each pixel and the "predicted" value for the pixel.  The predicted
  1411. value is a simple function of the already-transmitted pixels just above and
  1412. to the left of the current one (for example, their average; 8 different
  1413. predictor functions are permitted).  The sequence of differences is encoded
  1414. using the same back end (Huffman or arithmetic) used in the lossy mode.
  1415.  
  1416. Lossless JPEG with the Huffman back end is certainly not a state-of-the-art
  1417. lossless compression method, and wasn't even when it was introduced.  The
  1418. arithmetic-coding back end may make it competitive, but you're probably best
  1419. off looking at other methods if you need only lossless compression.
  1420.  
  1421. The main reason for providing a lossless option is that it makes a good
  1422. adjunct to the hierarchical mode: the final scan in a hierarchical sequence
  1423. can be a lossless coding of the remaining differences, to achieve overall
  1424. losslessness.  This isn't quite as useful as it may at first appear, because
  1425. exact losslessness is not guaranteed unless the encoder and decoder have
  1426. identical IDCT implementations (ie, identical roundoff errors).  And you
  1427. can't use downsampling or colorspace conversion either if you want true
  1428. losslessness.  But in some applications the combination is useful.
  1429.  
  1430.  
  1431. References:
  1432.  
  1433. For a good technical introduction to JPEG, see:
  1434.     Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  1435.     Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  1436. (Adjacent articles in that issue discuss MPEG motion picture compression,
  1437. applications of JPEG, and related topics.)  If you don't have the CACM issue
  1438. handy, a PostScript file containing a revised version of this article is
  1439. available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz.  This file
  1440. (actually a preprint for a later article in IEEE Trans. Consum. Elect.)
  1441. omits the sample images that appeared in CACM, but it includes corrections
  1442. and some added material.  Note: the Wallace article is copyright ACM and
  1443. IEEE, and it may not be used for commercial purposes.
  1444.  
  1445. An alternative, more leisurely explanation of JPEG can be found in "The Data
  1446. Compression Book" by Mark Nelson ([Nel 1991], see question 7).  This book
  1447. provides excellent introductions to many data compression methods including
  1448. JPEG, plus sample source code in C.  The JPEG-related source code is far from
  1449. industrial-strength, but it's a pretty good learning tool.
  1450.  
  1451. An excellent textbook about JPEG is "JPEG Still Image Data Compression
  1452. Standard" by William B. Pennebaker and Joan L. Mitchell.  Published by Van
  1453. Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  650 pages, price US$59.95.
  1454. (VNR will accept credit card orders at 800/842-3636, or get your local
  1455. bookstore to order it.)  This book includes the complete text of the ISO
  1456. JPEG standards, DIS 10918-1 and draft DIS 10918-2.  Review by Tom Lane:
  1457. "This is by far the most complete exposition of JPEG in existence.  It's
  1458. written by two people who know what they are talking about: both served on
  1459. the ISO JPEG standards committee.  If you want to know how JPEG works or
  1460. why it works that way, this is the book to have."
  1461.  
  1462. There are a number of errors in the first printing of the Pennebaker and
  1463. Mitchell book.  An errata list is available at
  1464. ftp://ftp.uu.net/graphics/jpeg/pm.errata.gz.  At last report, all known
  1465. errors were fixed in the second printing.
  1466.  
  1467. The official specification of JPEG is not currently available on-line, and
  1468. is not likely ever to be available for free because of ISO and ITU copyright
  1469. restrictions.  You can order it from your national standards agency as ISO
  1470. standards IS 10918-1, 10918-2, 10918-3, or as ITU-T standards T.81, T.83,
  1471. T.84.  See ftp://ftp.uu.net/graphics/jpeg/jpeg.documents.gz for more info.
  1472. NOTE: buying the Pennebaker and Mitchell textbook is a much better deal
  1473. than purchasing the standard directly: it's cheaper and includes a lot of
  1474. useful explanatory material along with the full draft text of the spec.
  1475. The book unfortunately doesn't include Part 3 of the spec, but if you need
  1476. Part 3, buy the book and just that part and you'll still be ahead.
  1477.  
  1478.  
  1479. ------------------------------------------------------------------------------
  1480.  
  1481. Subject: [76] What is Vector Quantization?
  1482.  
  1483. Some vector quantization software for data analysis that is available
  1484. in the ftp://cochlea.hut.fi/pub/ directory.  One package is lvq_pak and
  1485. one is som_pak (som_pak generates Kohonen maps of data using lvq to
  1486. cluster it).
  1487.  
  1488. A VQ-based codec that is based on the Predictive Residual Vector
  1489. Quantization is in ftp://mozart.eng.buffalo.edu/pub/prvq_codec/PRVQ.tar.gz
  1490.  
  1491. VQ software is also available in ftp://isdl.ee.washington.edu/pub/VQ/
  1492.  
  1493.  
  1494. For a book on Vector Quantization, see the reference (Gersho and Gray)
  1495. given in item 7 of this FAQ. For a review article: N. M. Nasrabadi and
  1496. R. A. King, "Image Coding Using Vector Quantization: A review",
  1497. IEEE Trans. on Communications, vol. COM-36, pp. 957-971, Aug. 1988.
  1498.  
  1499.  
  1500. A short introduction to Vector Quantization, written by Alex Zatsman
  1501. <alex.zatsman@analog.com>:
  1502.  
  1503. In Scalar  Quantization one represents  the values by  fixed subset of
  1504. representative values. For  examples, if you  have  16 bit  values and
  1505. send  only 8 most  signifcant bits, you  get an  approximation  of the
  1506. original data  at  the expense of  precision.  In this case  the fixed
  1507. subset is all the 16-bit numbers divisable by 256, i.e 0, 256, 512,...
  1508.  
  1509. In  Vector Quantization  you   represent   not individual values   but
  1510. (usually small) arrays of them. A typical  example  is a color  map: a
  1511. color picture can  be  represented by  a  2D array  of  triplets  (RGB
  1512. values). In most pictures  those triplets do  not cover the  whole RGB
  1513. space but  tend to   concetrate  in certain   areas. For  example, the
  1514. picture of a forest will typically have a lot of green. One can select
  1515. a relatively  small  subset (typically 256 elements) of representative
  1516. colors, i.e RGB  triplets,  and then approximate  each  triplet by the
  1517. representative of  that small set. In case  of 256 one  can use 1 byte
  1518. instead of 3 for each pixel.
  1519.  
  1520. One  can do   the  same   for  any large  data  sets,  especialy  when
  1521. consecutive points are correlated in some way. CELP speech compression
  1522. algorithms  use  those subsets  "codebooks" and   use them to quantize
  1523. exciation vectors  for linear prediction  -- hence the name CELP which
  1524. stands for Codebook Excited Linear Prediction.  (See item 26 in part 1
  1525. of this FAQ for more information about CELP.)
  1526.  
  1527. Note that Vector Quantization, just like Scalar Quantization, is a lossy
  1528. compression.
  1529.  
  1530. ------------------------------------------------------------------------------
  1531.  
  1532. Subject: [77] Introduction to Fractal compression (long)
  1533.  
  1534.  
  1535. Written by John Kominek <kominek@links.uwaterloo.ca>
  1536.  
  1537. Seven things you should know about Fractal Image Compression (assuming that 
  1538. you want to know about it).
  1539.  
  1540.    1. It is a promising new technology, arguably superior to JPEG -- 
  1541.       but only with an argument.
  1542.    2. It is a lossy compression method.
  1543.    3. The fractals in Fractal Image Compression are Iterated Function
  1544.       Systems.
  1545.    4. It is a form of Vector Quantization, one that employs a virtual
  1546.       codebook.
  1547.    5. Resolution enhancement is a powerful feature but is not some
  1548.       magical way of achieving 1000:1 compression.
  1549.    6. Compression is slow, decompression is fast.
  1550.    7. The technology is patented.
  1551.  
  1552. That's the scoop in condensed form. Now to elaborate, beginning with a little 
  1553. background.
  1554.  
  1555.  
  1556.  A Brief History of Fractal Image Compression
  1557.  --------------------------------------------
  1558.  
  1559. The birth of fractal geometry (or rebirth, rather) is usually traced to IBM 
  1560. mathematician Benoit B. Mandelbrot and the 1977 publication of his seminal 
  1561. book The Fractal Geometry of Nature. The book put forth a powerful thesis: 
  1562. traditional geometry with its straight lines and smooth surfaces does not 
  1563. resemble the geometry of trees and clouds and mountains. Fractal geometry, 
  1564. with its convoluted coastlines and detail ad infinitum, does.
  1565.  
  1566. This insight opened vast possibilities. Computer scientists, for one, found a 
  1567. mathematics capable of generating artificial and yet realistic looking land-
  1568. scapes, and the trees that sprout from the soil. And mathematicians had at 
  1569. their disposal a new world of geometric entities.
  1570.  
  1571. It was not long before mathematicians asked if there was a unity among this 
  1572. diversity. There is, as John Hutchinson demonstrated in 1981, it is the branch 
  1573. of mathematics now known as Iterated Function Theory. Later in the decade 
  1574. Michael Barnsley, a leading researcher from Georgia Tech, wrote the popular 
  1575. book Fractals Everywhere. The book presents the mathematics of Iterated Func-
  1576. tions Systems (IFS), and proves a result known as the Collage Theorem. The 
  1577. Collage Theorem states what an Iterated Function System must be like in order 
  1578. to represent an image.
  1579.  
  1580. This presented an intriguing possibility. If, in the forward direction, frac-
  1581. tal mathematics is good for generating natural looking images, then, in the 
  1582. reverse direction, could it not serve to compress images? Going from a given 
  1583. image to an Iterated Function System that can generate the original (or at 
  1584. least closely resemble it), is known as the inverse problem. This problem 
  1585. remains unsolved.
  1586.  
  1587. Barnsley, however, armed with his Collage Theorem, thought he had it solved. 
  1588. He applied for and was granted a software patent and left academia to found 
  1589. Iterated Systems Incorporated (US patent 4,941,193. Alan Sloan is the co-
  1590. grantee of the patent and co-founder of Iterated Systems.)  Barnsley announced 
  1591. his success to the world in the January 1988 issue of BYTE magazine. This 
  1592. article did not address the inverse problem but it did exhibit several images 
  1593. purportedly compressed in excess of 10,000:1. Alas, it was not a breakthrough. 
  1594. The images were given suggestive names such as "Black Forest" and "Monterey 
  1595. Coast" and "Bolivian Girl" but they were all manually constructed. Barnsley's 
  1596. patent has come to be derisively referred to as the "graduate student algo-
  1597. rithm."
  1598.  
  1599. Graduate Student Algorithm
  1600.    o Acquire a graduate student.
  1601.    o Give the student a picture.
  1602.    o And a room with a graphics workstation.
  1603.    o Lock the door.
  1604.    o Wait until the student has reverse engineered the picture.
  1605.    o Open the door.
  1606.  
  1607. Attempts to automate this process have met little success. As Barnsley admit-
  1608. ted in 1988: "Complex color images require about 100 hours each to encode and 
  1609. 30 minutes to decode on the Masscomp [dual processor workstation]." That's 100 
  1610. hours with a _person_ guiding the process.
  1611.  
  1612. Ironically, it was one of Barnsley's PhD students that made the graduate 
  1613. student algorithm obsolete. In March 1988, according to Barnsley, he arrived 
  1614. at a modified scheme for representing images called Partitioned Iterated 
  1615. Function Systems (PIFS). Barnsley applied for and was granted a second patent 
  1616. on an algorithm that can automatically convert an image into a Partitioned 
  1617. Iterated Function System, compressing the image in the process. (US patent 
  1618. 5,065,447. Granted on Nov. 12 1991.) For his PhD thesis, Arnaud Jacquin imple-
  1619. mented the algorithm in software, a description of which appears in his land-
  1620. mark paper "Image Coding Based on a Fractal Theory of Iterated Contractive 
  1621. Image Transformations." The algorithm was not sophisticated, and not speedy, 
  1622. but it was fully automatic. This came at price: gone was the promise of 
  1623. 10,000:1 compression. A 24-bit color image could typically be compressed from 
  1624. 8:1 to 50:1 while still looking "pretty good." Nonetheless, all contemporary 
  1625. fractal image compression programs are based upon Jacquin's paper.
  1626.  
  1627. That is not to say there are many fractal compression programs available. 
  1628. There are not. Iterated Systems sell the only commercial compressor/decompres-
  1629. sor, an MS-Windows program called "Images Incorporated." There are also an 
  1630. increasing number of academic programs being made freely available. Unfor-
  1631. tunately, these programs are -- how should I put it? -- of merely academic 
  1632. quality. 
  1633.  
  1634. This scarcity has much to do with Iterated Systems' tight lipped policy about 
  1635. their compression technology. They do, however, sell a Windows DLL for pro-
  1636. grammers. In conjunction with independent development by researchers else-
  1637. where, therefore, fractal compression will gradually become more pervasive. 
  1638. Whether it becomes all-pervasive remains to be seen.
  1639.  
  1640. Historical Highlights:
  1641.    1977 -- Benoit Mandelbrot finishes the first edition of The Fractal 
  1642.            Geometry of Nature.
  1643.    1981 -- John Hutchinson publishes "Fractals and Self-Similarity."
  1644.    1983 -- Revised edition of The Fractal Geometry of Nature is 
  1645.            published.
  1646.    1985 -- Michael Barnsley and Stephen Demko introduce Iterated
  1647.            Function Theory in "Iterated Function Systems and the Global
  1648.            Construction of Fractals."
  1649.    1987 -- Iterated Systems Incorporated is founded.
  1650.    1988 -- Barnsley publishes the book Fractals Everywhere.
  1651.    1990 -- Barnsley's first patent is granted.
  1652.    1991 -- Barnsley's second patent is granted.
  1653.    1992 -- Arnaud Jacquin publishes an article that describes the first
  1654.            practical fractal image compression method.
  1655.    1993 -- The book Fractal Image Compression by Michael Barnsley and Lyman 
  1656.            Hurd is published.
  1657.         -- The Iterated Systems' product line matures. 
  1658.    1994 -- Put your name here.
  1659.  
  1660.  
  1661.  On the Inside
  1662.  -------------
  1663.  
  1664. The fractals that lurk within fractal image compression are not those of the 
  1665. complex plane (Mandelbrot Set, Julia sets), but of Iterated Function Theory. 
  1666. When lecturing to lay audiences, the mathematician Heinz-Otto Peitgen intro-
  1667. duces the notion of Iterated Function Systems with the alluring metaphor of a 
  1668. Multiple Reduction Copying Machine. A MRCM is imagined to be a regular copying 
  1669. machine except that:
  1670.  
  1671.   1. There are multiple lens arrangements to create multiple overlapping
  1672.      copies of the original.
  1673.   2. Each lens arrangement reduces the size of the original.
  1674.   3. The copier operates in a feedback loop, with the output of one
  1675.      stage the input to the next. The initial input may be anything.
  1676.  
  1677. The first point is what makes an IFS a system. The third is what makes it 
  1678. iterative. As for the second, it is implicitly understood that the functions 
  1679. of an Iterated Function Systems are contractive. 
  1680.  
  1681. An IFS, then, is a set of contractive transformations that map from a defined 
  1682. rectangle of the real plane to smaller portions of that rectangle. Almost 
  1683. invariably, affine transformations are used. Affine transformations act to 
  1684. translate, scale, shear, and rotate points in the plane. Here is a simple 
  1685. example:
  1686.  
  1687.  
  1688.      |---------------|              |-----|
  1689.      |x              |              |1    |
  1690.      |               |              |     |
  1691.      |               |         |---------------|
  1692.      |               |         |2      |3      |
  1693.      |               |         |       |       |
  1694.      |---------------|         |---------------|  
  1695.  
  1696.          Before                      After
  1697.  
  1698.      Figure 1. IFS for generating Sierpinski's Triangle.
  1699.  
  1700. This IFS contains three component transformations (three separate lens ar-
  1701. rangements in the MRCM metaphor). Each one shrinks the original by a factor of 
  1702. 2, and then translates the result to a new location. It may optionally scale 
  1703. and shift the luminance values of the rectangle, in a manner similar to the 
  1704. contrast and brightness knobs on a TV.
  1705.  
  1706. The amazing property of an IFS is that when the set is evaluated by iteration, 
  1707. (i.e. when the copy machine is run), a unique image emerges. This latent image 
  1708. is called the fixed point or attractor of the IFS. As guaranteed by a result 
  1709. known as the Contraction Theorem, it is completely independent of the initial 
  1710. image. Two famous examples are Sierpinski's Triangle and Barnsley's Fern. 
  1711. Because these IFSs are contractive, self-similar detail is created at every 
  1712. resolution down to the infinitesimal. That is why the images are fractal.
  1713.  
  1714. The promise of using fractals for image encoding rests on two suppositions: 1. 
  1715. many natural scenes possess this detail within detail structure (e.g. clouds), 
  1716. and 2. an IFS can be found that generates a close approximation of a scene 
  1717. using only a few transformations. Barnsley's fern, for example, needs but 
  1718. four. Because only a few numbers are required to describe each transformation, 
  1719. an image can be represented very compactly. Given an image to encode, finding 
  1720. the optimal IFS from all those possible is known as the inverse problem.
  1721.  
  1722. The inverse problem -- as mentioned above -- remains unsolved. Even if it 
  1723. were, it may be to no avail. Everyday scenes are very diverse in subject 
  1724. matter; on whole, they do not obey fractal geometry. Real ferns do not branch 
  1725. down to infinity. They are distorted, discolored, perforated and torn. And the 
  1726. ground on which they grow looks very much different.
  1727.  
  1728. To capture the diversity of real images, then, Partitioned IFSs are employed. 
  1729. In a PIFS, the transformations do not map from the whole image to the parts, 
  1730. but from larger parts to smaller parts. An image may vary qualitatively from 
  1731. one area to the next (e.g. clouds then sky then clouds again). A PIFS relates 
  1732. those areas of the original image that are similar in appearance. Using Jac-
  1733. quin's notation, the big areas are called domain blocks and the small areas 
  1734. are called range blocks. It is necessary that every pixel of the original 
  1735. image belong to (at least) one range block. The pattern of range blocks is 
  1736. called the partitioning of an image.
  1737.  
  1738. Because this system of mappings is still contractive, when iterated it will 
  1739. quickly converge to its latent fixed point image. Constructing a PIFS amounts 
  1740. to pairing each range block to the domain block that it most closely resembles 
  1741. under some to-be-determined affine transformation. Done properly, the PIFS 
  1742. encoding of an image will be much smaller than the original, while still 
  1743. resembling it closely.
  1744.  
  1745. Therefore, a fractal compressed image is an encoding that describes:
  1746.    1. The grid partitioning (the range blocks).
  1747.    2. The affine transforms (one per range block).
  1748.  
  1749. The decompression process begins with a flat gray background. Then the set of 
  1750. transformations is repeatedly applied. After about four iterations the attrac-
  1751. tor stabilizes. The result will not (usually) be an exact replica of the 
  1752. original, but reasonably close.
  1753.  
  1754.  
  1755.  Scalelessnes and Resolution Enhancement
  1756.  ---------------------------------------
  1757.  
  1758. When an image is captured by an acquisition device, such as a camera or scan-
  1759. ner, it acquires a scale determined by the sampling resolution of that device. 
  1760. If software is used to zoom in on the image, beyond a certain point you don't 
  1761. see additional detail, just bigger pixels. 
  1762.  
  1763. A fractal image is different. Because the affine transformations are spatially 
  1764. contractive, detail is created at finer and finer resolutions with each itera-
  1765. tion. In the limit, self-similar detail is created at all levels of resolu-
  1766. tion, down the infinitesimal. Because there is no level that 'bottoms out' 
  1767. fractal images are considered to be scaleless.
  1768.  
  1769. What this means in practice is that as you zoom in on a fractal image, it will 
  1770. still look 'as it should' without the staircase effect of pixel replication. 
  1771. The significance of this is cause of some misconception, so here is the right 
  1772. spot for a public service announcement.
  1773.  
  1774.                         /--- READER BEWARE ---\
  1775.  
  1776. Iterated Systems is fond of the following argument. Take a portrait that is, 
  1777. let us say, a grayscale image 250x250 pixels in size, 1 byte per pixel. You 
  1778. run it through their software and get a 2500 byte file (compression ratio = 
  1779. 25:1). Now zoom in on the person's hair at 4x magnification. What do you see? 
  1780. A texture that still looks like hair. Well then, it's as if you had an image 
  1781. 1000x1000 pixels in size. So your _effective_ compression ratio is 25x16=400.
  1782.  
  1783. But there is a catch. Detail has not been retained, but generated. With a 
  1784. little luck it will look as it should, but don't count on it. Zooming in on a 
  1785. person's face will not reveal the pores. 
  1786.  
  1787. Objectively, what fractal image compression offers is an advanced form of 
  1788. interpolation. This is a useful and attractive property. Useful to graphic 
  1789. artists, for example, or for printing on a high resolution device. But it does 
  1790. not bestow fantastically high compression ratios.
  1791.  
  1792.                         \--- READER BEWARE ---/
  1793.  
  1794. That said, what is resolution enhancement? It is the process of compressing an 
  1795. image, expanding it to a higher resolution, saving it, then discarding the 
  1796. iterated function system. In other words, the compressed fractal image is the 
  1797. means to an end, not the end itself.
  1798.  
  1799.  
  1800.  The Speed Problem
  1801.  -----------------
  1802.  
  1803. The essence of the compression process is the pairing of each range block to a 
  1804. domain block such that the difference between the two, under an affine trans-
  1805. formation, is minimal. This involves a lot of searching. 
  1806.  
  1807. In fact, there is nothing that says the blocks have to be squares or even 
  1808. rectangles. That is just an imposition made to keep the problem tractable. 
  1809.  
  1810. More generally, the method of finding a good PIFS for any given image involves 
  1811. five main issues: 
  1812.    1. Partitioning the image into range blocks. 
  1813.    2. Forming the set of domain blocks. 
  1814.    3. Choosing type of transformations that will be considered. 
  1815.    4. Selecting a distance metric between blocks. 
  1816.    5. Specifying a method for pairing range blocks to domain blocks. 
  1817.  
  1818. Many possibilities exist for each of these. The choices that Jacquin offered 
  1819. in his paper are: 
  1820.    1. A two-level regular square grid with 8x8 pixels for the large
  1821.       range blocks and 4x4 for the small ones. 
  1822.    2. Domain blocks are 16x16 and 8x8 pixels in size with a subsampling 
  1823.       step size of four. The 8 isometric symmetries (four rotations, 
  1824.       four mirror flips) expand the domain pool to a virtual domain 
  1825.       pool eight times larger. 
  1826.    3. The choices in the last point imply a shrinkage by two in each 
  1827.       direction, with a possible rotation or flip, and then a trans-
  1828.       lation in the image plane. 
  1829.    4. Mean squared error is used. 
  1830.    5. The blocks are categorized as of type smooth, midrange, simple
  1831.       edge, and complex edge. For a given range block the respective
  1832.       category is searched for the best match.
  1833.  
  1834. The importance of categorization can be seen by calculating the size of the 
  1835. total domain pool. Suppose the image is partitioned into 4x4 range blocks. A 
  1836. 256x256 image contains a total of (256-8+1)^2  = 62,001 different 8x8 domain 
  1837. blocks. Including the 8 isometric symmetries increases this total to 496,008. 
  1838. There are (256-4+1)^2 = 64,009 4x4 range blocks, which makes for a maximum of 
  1839. 31,748,976,072 possible pairings to test. Even on a fast workstation an ex-
  1840. haustive search is prohibitively slow. You can start the program before de-
  1841. parting work Friday afternoon; Monday morning, it will still be churning away. 
  1842.  
  1843. Increasing the search speed is the main challenge facing fractal image com-
  1844. pression.
  1845.  
  1846.  
  1847.  Similarity to Vector Quantization
  1848.  ---------------------------------
  1849.  
  1850. To the VQ community, a "vector" is a small rectangular block of pixels. The 
  1851. premise of vector quantization is that some patterns occur much more frequent-
  1852. ly than others. So the clever idea is to store only a few of these common 
  1853. patterns in a separate file called the codebook. Some codebook vectors are 
  1854. flat, some are sloping, some contain tight texture, some sharp edges, and so 
  1855. on -- there is a whole corpus on how to construct a codebook. Each codebook 
  1856. entry (each domain block) is assigned an index number. A given image, then, is 
  1857. partitioned into a regular grid array. Each grid element (each range block) is 
  1858. represented by an index into the codebook. Decompressing a VQ file involves 
  1859. assembling an image out of the codebook entries. Brick by brick, so to speak.
  1860.  
  1861. The similarity to fractal image compression is apparent, with some notable 
  1862. differences. 
  1863.    1. In VQ the range blocks and domain blocks are the same size; in an
  1864.       IFS the domain blocks are always larger. 
  1865.    2. In VQ the domain blocks are copied straight; in an IFS each domain 
  1866.       block undergoes a luminance scaling and offset.
  1867.    3. In VQ the codebook is stored apart from the image being coded; in 
  1868.       an IFS the codebook is not explicitly stored. It is comprised of
  1869.       portions of the attractor as it emerges during iteration. For that
  1870.       reason it is called a "virtual codebook." It has no existence
  1871.       independent of the affine transformations that define an IFS.
  1872.    4. In VQ the codebook is shared among many images; in an IFS the 
  1873.       virtual codebook is specific to each image.
  1874.  
  1875. There is a more refined version of VQ called gain-shape vector quantization in 
  1876. which a luminance scaling and offset is also allowed. This makes the similari-
  1877. ty to fractal image compression as close as can be.
  1878.  
  1879.  
  1880.  Compression Ratios
  1881.  ------------------
  1882.  
  1883. Exaggerated claims not withstanding, compression ratios typically range from 
  1884. 4:1 to 100:1. All other things equal, color images can be compressed to a 
  1885. greater extent than grayscale images.
  1886.  
  1887. The size of a fractal image file is largely determined by the number of trans-
  1888. formations of the PIFS. For the sake of simplicity, and for the sake of com-
  1889. parison to JPEG, assume that a 256x256x8 image is partitioned into a regular 
  1890. partitioning of 8x8 blocks. There are 1024 range blocks and thus 1024 trans-
  1891. formations to store. How many bits are required for each?
  1892.  
  1893. In most implementations the domain blocks are twice the size of the range 
  1894. blocks. So the spatial contraction is constant and can be hard coded into the 
  1895. decompression program. What needs to be stored are:
  1896.  
  1897.    x position of domain block        8     6
  1898.    y position of domain block        8     6
  1899.    luminance scaling                 8     5
  1900.    luminance offset                  8     6
  1901.    symmetry indicator                3     3
  1902.                                     --    --
  1903.                                     35    26 bits
  1904.  
  1905. In the first scheme, a byte is allocated to each number except for the symme-
  1906. try indicator. The upper bound on the compression ratio is thus (8x8x8)/35 = 
  1907. 14.63. In the second scheme, domain blocks are restricted to coordinates 
  1908. modulo 4. Plus, experiments have revealed that 5 bits per scale factor and 6 
  1909. bits per offset still give good visual results. So the compression ratio limit 
  1910. is now 19.69. Respectable but not outstanding.
  1911.  
  1912. There are other, more complicated, schemes to reduce the bit rate further. The 
  1913. most common is to use a three or four level quadtree structure for the range 
  1914. partitioning. That way, smooth areas can be represented with large range 
  1915. blocks (high compression), while smaller blocks are used as necessary to 
  1916. capture the details. In addition, entropy coding can be applied as a back-end 
  1917. step to gain an extra 20% or so.
  1918.  
  1919.  
  1920.  Quality: Fractal vs. JPEG
  1921.  -------------------------
  1922.  
  1923. The greatest irony of the coding community is that great pains are taken to 
  1924. precisely measure and quantify the error present in a compressed image, and 
  1925. great effort is expended toward minimizing an error measure that most often is 
  1926. -- let us be gentle -- of dubious value. These measure include signal-to-noise 
  1927. ratio, root mean square error, and mean absolute error. A simple example is 
  1928. systematic shift: add a value of 10 to every pixel. Standard error measures 
  1929. indicate a large distortion, but the image has merely been brightened.
  1930.  
  1931. With respect to those dubious error measures, and at the risk of over-sim-
  1932. plification, the results of tests reveal the following: for low compression 
  1933. ratios JPEG is better, for high compression ratios fractal encoding is better. 
  1934. The crossover point varies but is often around 40:1. This figure bodes well 
  1935. for JPEG since beyond the crossover point images are so severely distorted 
  1936. that they are seldom worth using. 
  1937.  
  1938. Proponents of fractal compression counter that signal-to-noise is not a good 
  1939. error measure and that the distortions present are much more 'natural looking' 
  1940. than the blockiness of JPEG, at both low and high bit rates. This is a valid 
  1941. point but is by no means universally accepted. 
  1942.  
  1943. What the coding community desperately needs is an easy to compute error meas-
  1944. ure that accurately captures subjective impression of human viewers. Until 
  1945. then, your eyes are the best judge.
  1946.  
  1947.  
  1948.  Finding Out More
  1949.  ----------------
  1950.  
  1951.  Please refer to item 17 in part 1 of this FAQ for a list of references,
  1952. available software, and ftp sites concerning fractal compression.
  1953.  
  1954. ------------------------------------------------------------------------------
  1955.  
  1956. Subject: [78] The Burrows-Wheeler block sorting algorithm (long)
  1957.  
  1958.  
  1959. A high-quality implementation of the Burrows-Wheeler
  1960. block-sorting-based lossless compression algorithm is available at
  1961. http://www.cs.man.ac.uk/arch/people/j-seward/bzip-0.21.tar.gz
  1962.  
  1963. Mark Nelson wrote an excellent article "Data Compression with the
  1964. Burrows-Wheeler Transform" for Dr. Dobb's Journal, September 1996.  A copy
  1965. of the article is at http://www.dogma.net/markn/articles/bwt/bwt.htm
  1966.  
  1967. Another introduction written by Sampo Syreeni <tmaaedu@nexus.edu.lahti.fi>:
  1968.  
  1969.     The Burrows-Wheeler block sorting compression algorithm is described in
  1970. "A Block-sorting Lossless Data Compression Algorithm" by M. Burrows and D.J.
  1971. Wheeler, dated in May 10, 1994. A postscript copy of this paper has been made
  1972. available by Digital on the Systems Research Center (SRC) FTP site at
  1973. ftp://ftp.digital.com/pub/DEC/SRC/research-reports/SRC-124.ps.Z
  1974.  
  1975.     The method was originally discovered by one of the authors (Wheeler) back
  1976. in 1983, but has not been published before. As such, the method is fairly new
  1977. and hasn't yet gained popularity.
  1978.  
  1979.     The method described in the original paper is really a composite of three
  1980. different algorithms: the block sorting main engine (a lossless, very slightly
  1981. expansive preprocessor), the move-to-front coder (a byte-for-byte simple,
  1982. fast, locally adaptive noncompressive coder) and a simple statistical
  1983. compressor (first order Huffman is mentioned as a candidate) eventually doing
  1984. the compression. Of these three methods only the first two are discussed here
  1985. as they are what constitutes the heart of the algorithm. These two algorithms
  1986. combined form a completely reversible (lossless) transformation that - with
  1987. typical input - skews the first order symbol distributions to make the data
  1988. more compressible with simple methods. Intuitively speaking, the method
  1989. transforms slack in the higher order probabilities of the input block (thus
  1990. making them more even, whitening them) to slack in the lower order statistics.
  1991. This effect is what is seen in the histogram of the resulting symbol data.
  1992.  
  1993.     The block sorting preprocessor operates purely on a block basis. One way
  1994. to understand the idea is to think of the input block arranged as a circular
  1995. array where, for every symbol, the succeeding symbols are used as a predictor.
  1996. This predictor is then used to group the symbols with similar right neighbors
  1997. together. This predictor is realized (conceptually) as a two phase process.
  1998. The first phase forms all cyclic shifts of the input block whose size is
  1999. usually a power of two. Note here that the original string is always present
  2000. intact on some row of the resulting matrix. If the block length is n then
  2001. there exist n unique rotations of the original string (to the left). These
  2002. rotations are now viewed as the rows of an N x N matrix of symbols. The second
  2003. phase consists of sorting this resulting conceptual matrix. This phase results
  2004. in the rows coming into order based on their first few symbols. If there is
  2005. some commonly repeated string in the input block (the original paper gives
  2006. "the" as an example), the sorting phase brings all those rotations that have a
  2007. part of this string as the row start very close to each other. The preceding
  2008. symbol in this common string is then found in the last column of the sorted
  2009. matrix. This way common strings result in short bursts of just a few distinct
  2010. characters being formed in the last column of the matrix. The last column is
  2011. what is then output from the second phase. One further bit of information is
  2012. derived from the input data. This is an integer with enough bits to tell the
  2013. size of the input string (that is, log_2(n)). The number is used to note the
  2014. row position into which the original input block got in the sorting algorithm.
  2015. This integer always results in expansion of the data, but is necessary for us
  2016. to be able successfully decompress the string. The absolute amount of overhead
  2017. increases as the logarithm of the input block size so its percentage of the
  2018. output data becomes negligible with useful block sizes anyway.
  2019.  
  2020.     The characteristics of the transformation process make the output from the
  2021. sort ideal for certain kinds of further manipulation. The extreme local
  2022. fluctuations in the first order statistics of the output string lead one to
  2023. use a transformation that boosts and flattens the local fluttering of the
  2024. statistics. The best example (and, of course, the one given in the original
  2025. paper) is move-to-front coding. This coder codes a symbol as the number of
  2026. distinct symbols seen since the symbol's last occurrence. Basically this means
  2027. that the coder outputs the index of an input symbol in a dynamic LIFO stack
  2028. and then updates the stack by moving the symbol to the top. This is easy and
  2029. efficient to implement and results in fast local adaptation. As just a few
  2030. common symbols will (locally) govern the input to the coder, these symbols
  2031. will be kept on the top of the stack and thus the output will mainly consist
  2032. of low numbers. This makes it highly susceptible to first order statistical
  2033. compression methods which are, in case, easy and efficient to implement.
  2034.  
  2035.     The transform matrix described above would require enormous amounts of
  2036. storage space and would not result in a usable algorithm as such. The method
  2037. can, however, be realized very efficiently by suffix and quick sort methods.
  2038. Thus the whole transformation together with the eventual simple compression
  2039. engine is extremely fast but still achieves impressive compression on typical
  2040. input data. When implemented well, the speeds achieved can be in the order of
  2041. pure LZ and the compression ratios can still approach state-of-the-art Markov
  2042. modeling coders. The engine also responds well to increasing block sizes -
  2043. the longer the input block, the more space there is for the patterns to form
  2044. and the more similar input strings there will be in it. This results in almost
  2045. monotonously increasing compression ratios even as the block length goes well
  2046. into the megabyte range.
  2047.     The decompression cascade is basically just the compression cascade
  2048. backwards. More logic is needed to reverse the main sorting stage, however.
  2049. This logic involves reasoning around the order of the first the last column of
  2050. the conceptual coding matrix. The reader is referred to the original paper for
  2051. an in depth treatment of the subject. The original paper also contains a more
  2052. thorough discussion of why the method works and how to implement it.
  2053.  
  2054.     And now a little demonstration. The original block to be compressed is
  2055. chosen to be the (rather pathological) string "good, jolly good". This was
  2056. taken as an example because it has high redundancy and it is exactly 16 bytes
  2057. long. The first picture shows the cyclic shifts (rotations) of the input
  2058. string. The second shows the matrix after sorting. Note that the last column
  2059. now has many double characters in it. Note also that the original string has
  2060. been placed into the 6th row now. The third picture shows the output for this
  2061. input block. The index integer has been packed to a full byte although 4 bits
  2062. would suffice in this case (log_2(16)=4). The fourth and fifth pictures show
  2063. the transformed string after move-to-front-coding. The sixth picture shows the
  2064. statistical distribution of the characters in the output string. Notice the
  2065. disproportionately large amount of ones and zeros, even with a very short
  2066. string like this. This is the output that is then routed through the simple
  2067. statistical encoder. It should compress very well, as the distribution of the
  2068. characters in the input block is now very uneven.
  2069.  
  2070.  
  2071.       0 1 2 3 4 5 6 7 8 9 A B C D E F        0 1 2 3 4 5 6 7 8 9 A B C D E F
  2072.       -------------------------------        -------------------------------
  2073.   0 | g o o d ,   j o l l y   g o o d    0 |   g o o d g o o d ,   j o l l y
  2074.   1 | o o d ,   j o l l y   g o o d g    1 |   j o l l y   g o o d g o o d ,
  2075.   2 | o d ,   j o l l y   g o o d g o    2 | ,   j o l l y   g o o d g o o d
  2076.   3 | d ,   j o l l y   g o o d g o o    3 | d ,   j o l l y   g o o d g o o
  2077.   4 | ,   j o l l y   g o o d g o o d    4 | d g o o d ,   j o l l y   g o o
  2078.   5 |   j o l l y   g o o d g o o d ,    5 | g o o d ,   j o l l y   g o o d
  2079.   6 | j o l l y   g o o d g o o d ,      6 | g o o d g o o d ,   j o l l y
  2080.   7 | o l l y   g o o d g o o d ,   j    7 | j o l l y   g o o d g o o d ,
  2081.   8 | l l y   g o o d g o o d ,   j o    8 | l l y   g o o d g o o d ,   j o
  2082.   9 | l y   g o o d g o o d ,   j o l    9 | l y   g o o d g o o d ,   j o l
  2083.   A | y   g o o d g o o d ,   j o l l    A | o d ,   j o l l y   g o o d g o
  2084.   B |   g o o d g o o d ,   j o l l y    B | o d g o o d ,   j o l l y   g o
  2085.   C | g o o d g o o d ,   j o l l y      C | o l l y   g o o d g o o d ,   j
  2086.   D | o o d g o o d ,   j o l l y   g    D | o o d ,   j o l l y   g o o d g
  2087.   E | o d g o o d ,   j o l l y   g o    E | o o d g o o d ,   j o l l y   g
  2088.   F | d g o o d ,   j o l l y   g o o    F | y   g o o d g o o d ,   j o l l
  2089.  
  2090.              1. The shifts                    2. In lexicographic order
  2091.  
  2092.  
  2093.                                                 121,45,102,114,0,1,36,0,
  2094.          "y,dood  oloojggl",5                   1,113,1,0,112,110,0,3,5
  2095.  
  2096.      3. The output from block sort          4. After move-to-front-coding
  2097.  
  2098.  
  2099.                                              00: 4;  01: 3;  03: 1;  05: 1;
  2100.           79,2D,66,72,0,1,24,0,              24: 1;  2D: 1;  66: 1;  6E: 1;
  2101.           1,71,1,0,70,6E,0,3,5               70: 1;  71: 1;  72: 1;  79: 1
  2102.  
  2103.            5. In hexadecimal                      6. The statistics
  2104.  
  2105. ------------------------------------------------------------------------------
  2106.  
  2107.           End of part 2 of the comp.compression faq.
  2108.