home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Information / Specifications / Data / Compression / compression-faq⁄part2 < prev    next >
Encoding:
Text File  |  1994-12-08  |  85.6 KB  |  1,765 lines  |  [BINA/R*ch]

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