Changes between Version 10 and Version 11 of img2twit


Ignore:
Timestamp:
05/25/2009 12:35:27 PM (15 years ago)
Author:
Sam Hocevar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • img2twit

    v10 v11  
    33The first I read about this "competition" was [http://www.flickr.com/photos/quasimondo/3518306770/in/set-72057594062596732/ here].
    44
    5 = Discussion =
     5= How it works =
    66
    7 == Bit availability ==
     7My goal is to reach a reasonable compromise between the following:
     8 * Allow fast decompression
     9 * Achieve decent reconstruction quality
     10 * Work with various message length and character sets
     11 * Do not waste a single bit of information
    812
    9 Twitter allows for 140 characters in a message. UTF-8 is allowed.
     13Here is a rough overview of the encoding process:
     14 * The number of available bits is computed from desired message length and usable charset
     15 * The source image is segmented into as many square cells as the available bits permit
     16 * A fixed number of points (currently 2) is affected to each cell, currently by selecting the darkest and brightest pixels in the cell
     17 * The following is repeated until a quality condition is met:
     18   * A point is chosen a random
     19   * An operation is performed at random on this point (moving it inside its cell, changing its colour)
     20   * If the resulting image (see the decoding process below) is closer to the source image, the operation is kept
     21 * The image size and list of points is encoded in UTF-8
    1022
    11 UTF-8 is restricted to the formal Unicode definition by RFC 3629. It means that the only legal UTF-8 characters range from U+0000 to U+10FFFF. The following restrictions must also be added:
    12  * The 2¹¹ high and low surrogates, used for UTF-16 encoding, restricting the Unicode range to U+0000..U+D7FF and U+E000..U+10FFFF.
    13  * The 66 non-characters.
     23And this is the decoding process:
     24 * The image size and points are read from the UTF-8 stream
     25 * For each pixel in the destination image:
     26   * The list of natural neigbours is computed
     27   * The pixel's final colour is set as a weighted average of its natural neighbours' colours
    1428
    15 The final size of this set is:
     29== Bit allocation ==
     30
     31UTF-8 is restricted to the formal Unicode definition by RFC 3629, meaning that once the 2¹¹ high and low surrogates and the 66 non-characters are removed from the U+0000..U+10FFFF range, the final size of the UTF-8 character set is 1111998. However, a lot of these characters are undefined, not yet allocated or are control characters. As of Unicode 5.1 there are only 100507 graphic characters.
     32
     33The number of bits that can be expressed in a 140-character message using this charset is:
    1634
    1735{{{
    1836#!latex
    19 $(2^{20} + 2^{16}) - 2^{11} - 66 = 1111998$
     37$n_{bits} = \dfrac{140 \log(100507)}{\log(2)} = 2326.37$
    2038}}}
    2139
    22 The number of bits that can be encoded using 140 such characters is computed as follows:
     40If we restrict ourselves to the 20902 characters available in the ''CJK Unified Ideographs'' block, the number of bits becomes:
    2341
    2442{{{
    2543#!latex
    26 $n_{bits} = \mathrm{floor}\left(\dfrac{140 \log(1111998)}{\log(2)}\right) = 2811$
     44$n_{bits} = \dfrac{140 \log(20902)}{\log(2)} = 2009.18$
    2745}}}
    2846
    29 In theory, 2811 bits is therefore the maximum we can stuff into a Twitter message. However, a lot of these characters are undefined, not yet allocated or are control characters. As of Unicode 5.1 there are 100507 graphic characters, reducing the number of expressed bits to:
     47And finally, using the 94 non-spacing, printable ASCII characters:
    3048
    3149{{{
    3250#!latex
    33 $n_{bits} = \mathrm{floor}\left(\dfrac{140 \log(100507)}{\log(2)}\right) = 2326$
     51$n_{bits} = \dfrac{140 \log(94)}{\log(2)} = 917.64$
    3452}}}
    3553
    36 We'll go on with this value of 2326 encodable bits.
     54== Optimised bitstream ==
    3755
    38 == Bit allocation ==
    39 
    40 A compressed image usually contains the following information:
    41  * The image geometry information (width and height)
    42  * Optional colour information (palette)
    43  * Elementary picture elements (encoded as pixels, triangles, vectors...)
    44 
    45 Given the amount of compression we are doing, there is little point in compressing images larger than 512×512. This reduces image geometry information to 18 bits, leaving us with 2308 bits to encode the image information.
    46 
    47 Whether to use a palette or to encode colour information into the picture elements is undecided yet. We'll cover both options.
    48 
    49 == Strategy 1: colour information in picture elements ==
    50 
    51 Each picture element will hold data for:
    52  * coordinates
    53  * colour information
    54  * additional control information
    55 
    56 Coordinates could be absolute (therefore requiring 16 or 14 bits, maybe 12) or relative. I would favour a coordinate system relative to predefined image cells because there is a good chance that each cell will hold a point. Assuming at least 8 horizontal and vertical subdivisions, 6 bits can be gained this way. The final coordinate bit allocation is now 10, 8 or 6. We'll pick 8 to be safe for now: 16 X values and 16 Y values.
    57 
    58 Using 7 bits per colour allows for the following options:
    59  * full bit range usage: 4 red values, 8 green values, 4 blue values
    60  * almost full bit range usage: 5 red values, 5 green values, 5 blue values
    61 
    62 Finally, a weight value could be added, using a final bit.
    63 
    64 The proposed allocation is then 16, allowing 144 points to be stored in the following configurations:
    65  * 12×12
    66  * 10×14 (wasting 4 point slots)
    67  * 9×16
    68  * 8×18
    69  * 7×20 (wasting 4 point slots)
    70  * 6×24
    71 
    72 == Strategy 2: colour information in a separate palette ==
    73 
    74 ''To do.''
    75 
    76 == Image reconstruction ==
    77 
    78 Image reconstruction is an interpolation problem on a Delaunay triangulation. We use the natural neighbour coordinates to interpolate between nodes and obtain a first-order smooth image.
     56''Todo''
    7957
    8058= Preliminary results =