Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #546631

Re: data compression algorithm

From Martin Brown <'''newspam'''@nezumi.demon.co.uk>
Newsgroups sci.electronics.design
Subject Re: data compression algorithm
Date 2019-06-10 09:10 +0100
Organization Aioe.org NNTP Server
Message-ID <qdl3ah$1ar5$1@gioia.aioe.org> (permalink)
References <8JbLE.9929$t_3.6270@fx18.iad> <jplqfe5rq7af3b0bctjts5tta1pqucptp3@4ax.com>

Show all headers | View raw


On 09/06/2019 20:03, John Larkin wrote:
> On Sun, 9 Jun 2019 13:54:11 -0400, bitrex <user@example.net> wrote:
> 
>> In the vein of suggestions made by Martin Brown, David Eather, et al a
>> while back, this is idea for a lossy compressor/decompressor designed to
>> compress 10 bits of greyscale image data down to 8 in a semi-logarithmic
>> way.
>>
>> To avoid taking a square root on the output side the lossy
>> "decompressor", such as it is, is two iterations of a modified Newton's
>> method to compute the inverse.
>>
>> Since the compression function is nearly linear when its input is
>> small-valued using the 8 bit compressed value as the starting guess for
>> the inverse helps prevent Newton from hunting over across the
>> discontinuity in the input function, on the wrong side of the Y axis
>>
>>
>> #include <cstdint>
>>
>> //family of curves of the form x = int( 0.5+k*y*(A + By)/(A + Cy))
>>
>> constexpr auto compress(uint16_t y) -> uint8_t {
>>    //tweak "k" to taste to avoid overflow
>>    return 0.5 + 0.997 * y * (4096 + y) / (4096 + 32 * y);
>> }

You really ought to do it in scaled integer arithmetic! Or lookup table.

0.5 converted to a fraction over A+Cy gives

x = int( (A/2 + y*(A+C/2 + By))/(A' + Cy)

k can be absorbed into A' ~ 4108


>> auto decompress(uint8_t x) -> uint16_t {
>>    auto f_y = [x](uint16_t y) { return compress(y) - x; };
>>
>>    auto f_y_prime = [](uint16_t y) {
>>      return (16351.2 + 7.984 * y + 0.0311875 * y * y) / ((128 + y) *
>> (128 + y));
>>    };
>>
>>    const uint16_t y_init = x;
>>
>>    auto y = y_init - f_y(y_init) / f_y_prime(y_init);
>>    y = y - f_y(y) / f_y_prime(0.5*(y + y_init));
>>    auto y_prime = y - f_y(y) / f_y_prime(y);
>>    return y - f_y(y) / f_y_prime(0.5*(y + y_prime));
>> }
> 
> 
> Lookup tables would be easy.

+1

I had always assumed that on the decode side the mapping for the 256 
values transmitted would be converted back using a lookup table computed 
locally or sent by the data source as a header on the image info.

Lookup tables are just so much easier. Also remember that you want to 
return the mid value of the band of source data that mapped to a 
particular 8 bit index or you will introduce bias.
> 
> We do FPGA and uP based functions with lookups, and sometimes a bit of
> interpolation. Like for DDS sine waves.



-- 
Regards,
Martin Brown

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

data compression algorithm bitrex <user@example.net> - 2019-06-09 13:54 -0400
  Re: data compression algorithm John Larkin <jjlarkin@highlandtechnology.com> - 2019-06-09 12:03 -0700
    Re: data compression algorithm bitrex <user@example.net> - 2019-06-09 17:27 -0400
      Re: data compression algorithm bitrex <user@example.net> - 2019-06-09 17:31 -0400
        Re: data compression algorithm John Doe <always.look@message.header> - 2019-06-09 22:05 +0000
          Re: data compression algorithm bitrex <user@example.net> - 2019-06-09 18:10 -0400
          Re: data compression algorithm John Larkin <jjlarkin@highlandtechnology.com> - 2019-06-09 16:36 -0700
            Re: data compression algorithm bitrex <user@example.net> - 2019-06-09 19:43 -0400
              Re: data compression algorithm John Larkin <jjlarkin@highlandtechnology.com> - 2019-06-10 07:12 -0700
                Re: data compression algorithm Rick C <gnuarm.deletethisbit@gmail.com> - 2019-06-10 07:32 -0700
                Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 10:42 -0400
                Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 10:49 -0400
    Re: data compression algorithm Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2019-06-10 09:10 +0100
      Re: data compression algorithm John Larkin <jjlarkin@highlandtechnology.com> - 2019-06-10 07:17 -0700
        Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 11:03 -0400
      Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 11:11 -0400
        Re: data compression algorithm John Doe <always.look@message.header> - 2019-06-10 17:23 +0000
          Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 15:07 -0400
          Re: data compression algorithm bitrex <user@example.net> - 2019-06-10 15:31 -0400
            Re: data compression algorithm John Doe <always.look@message.header> - 2019-06-11 15:07 +0000
              Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 11:40 -0400
              Re: data compression algorithm John Larkin <jjlarkin@highland_snip_technology.com> - 2019-06-11 10:13 -0700
                Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 14:41 -0400
        Re: data compression algorithm Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2019-06-11 14:47 +0100
          Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 11:41 -0400
            Re: data compression algorithm Winfield Hill <winfieldhill@yahoo.com> - 2019-06-11 10:28 -0700
              Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 14:31 -0400
              Re: data compression algorithm Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2019-06-11 19:56 +0100
                Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 15:32 -0400
                Re: data compression algorithm Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2019-06-12 09:11 +0100
                Re: data compression algorithm bitrex <user@example.net> - 2019-06-12 11:33 -0400
          Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 11:42 -0400
          Re: data compression algorithm John Larkin <jjlarkin@highland_snip_technology.com> - 2019-06-11 13:16 -0700
            Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 17:20 -0400
            Re: data compression algorithm bitrex <user@example.net> - 2019-06-11 17:30 -0400
    Re: data compression algorithm david eather <eatDELETEher@tpg.com.au> - 2019-06-12 11:05 +1000

csiph-web