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


Groups > sci.electronics.design > #546555 > unrolled thread

data compression algorithm

Started bybitrex <user@example.net>
First post2019-06-09 13:54 -0400
Last post2019-06-12 11:05 +1000
Articles 16 on this page of 36 — 8 participants

Back to article view | Back to sci.electronics.design


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#546793

Frombitrex <user@example.net>
Date2019-06-11 11:40 -0400
Message-ID<lXPLE.29703$cZ6.25501@fx47.iad>
In reply to#546787
On 6/11/19 11:07 AM, John Doe wrote:
> This troll loves responding twice to every post,
> even its own...
> 

Do you like girls, son?

[toc] | [prev] | [next] | [standalone]


#546805

FromJohn Larkin <jjlarkin@highland_snip_technology.com>
Date2019-06-11 10:13 -0700
Message-ID<j8ovfetfft5t9kf3646gri88d2lvvj4u0p@4ax.com>
In reply to#546787
On Tue, 11 Jun 2019 15:07:53 -0000 (UTC), John Doe
<always.look@message.header> wrote:

>This troll loves responding twice to every post, 
>even its own...

His true love is himself.


-- 

John Larkin         Highland Technology, Inc
picosecond timing   precision measurement 

jlarkin att highlandtechnology dott com
http://www.highlandtechnology.com

[toc] | [prev] | [next] | [standalone]


#546822

Frombitrex <user@example.net>
Date2019-06-11 14:41 -0400
Message-ID<1BSLE.23387$kt.9875@fx06.iad>
In reply to#546805
On 6/11/19 1:13 PM, John Larkin wrote:
> On Tue, 11 Jun 2019 15:07:53 -0000 (UTC), John Doe
> <always.look@message.header> wrote:
> 
>> This troll loves responding twice to every post,
>> even its own...
> 
> His true love is himself.
> 
> 

At least I have a sense of humor :) John Doe sadly has none. Just 
engineering-content-free habitual OT rants on the people he doesn't like 
who he'd like someone else to kill for him this week.

feel free to be pals with him, it's cool...

[toc] | [prev] | [next] | [standalone]


#546779

FromMartin Brown <'''newspam'''@nezumi.demon.co.uk>
Date2019-06-11 14:47 +0100
Message-ID<qdobec$1utp$1@gioia.aioe.org>
In reply to#546661
On 10/06/2019 16:11, bitrex wrote:
> On 6/10/19 4:10 AM, Martin Brown wrote:
>> 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
> 
> The encoding side is running on a desktop-class PC don't need any lookup 
> table there.

If you have plenty of time on the encode side you might want to consider 
another more costly form of data adaptive 12 bit to 8 bit encoding which 
is based on greedy histogram equalisation. It requires an array to count 
the frequency of every pixel value in the image and then multiple sweeps 
of that to determine a histogram equalisation with ever increasing bin 
widths to allocate the bins.

Initially you start with binsize=1 and Nbins= 256

target = Npixels/Nbins

It works very well on images with a lot of baseline values and a few 
features. You have to transmit a lookup table with the byte values.

It is very good for looking for systematic errors on flat fields.

BTW You haven't said if the 8 bit comms was able to keep up.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#546794

Frombitrex <user@example.net>
Date2019-06-11 11:41 -0400
Message-ID<6ZPLE.29704$cZ6.16587@fx47.iad>
In reply to#546779
On 6/11/19 9:47 AM, Martin Brown wrote:
> On 10/06/2019 16:11, bitrex wrote:
>> On 6/10/19 4:10 AM, Martin Brown wrote:
>>> 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
>>
>> The encoding side is running on a desktop-class PC don't need any 
>> lookup table there.
> 
> If you have plenty of time on the encode side you might want to consider 
> another more costly form of data adaptive 12 bit to 8 bit encoding which 
> is based on greedy histogram equalisation. It requires an array to count 
> the frequency of every pixel value in the image and then multiple sweeps 
> of that to determine a histogram equalisation with ever increasing bin 
> widths to allocate the bins.
> 
> Initially you start with binsize=1 and Nbins= 256
> 
> target = Npixels/Nbins
> 
> It works very well on images with a lot of baseline values and a few 
> features. You have to transmit a lookup table with the byte values.
> 
> It is very good for looking for systematic errors on flat fields.
> 
> BTW You haven't said if the 8 bit comms was able to keep up.
> 

Yes, for reasonably-sized amounts of greyscale video data the serial 
link works extremely well. my test case was sendiing 256 pixels of 10 
bit greyscale data over serial @ 57600 baud, 10 bits packed to 8 as 
described, and then writing out to a small LCD display on the fly.

It's written out line-by-line with COBS encoding and a two-byte 
Fletcher16 checksum appended to each line of data beforehand, with a 
"vertical sync" byte sent at the start of each frame, so the uP can sync 
up to the datastream and knows when to start filling the frame buffer.

There are two "threads" on the uP, one that handles writing lines into 
frame buffer 1, and one that handles writing out a full frame buffer to 
the display from frame buffer 2. when the input frame buffer is full and 
the output is empty the pointers are swapped. The data-reception thread 
is given priority to momentarily pause the write-out to the display 
while it grabs incoming data

The checksum-per-line system was necessary because at least with the 
hardware I have, at 57600 baud, maybe 5-8% of the packets show up with 
burst errors that make them unusable and have to be discarded. Trying to 
write out a whole frame of 256 bytes at once with a 4 byte checksum for 
the whole frame almost guaranteed there'd be a bungled bit somewhere and 
the checksum would be incorrect, and never got a correct frame.

With the system as I have it now, no lookup table just the code I 
posted, I can get about 20-25 fps of 256 pixel decoded 10 bit greyscale 
image data received, decoded, and put onto the LCD display on an 8 bit 
16 MHz Arduino-type board no problem at all, running for several days 
hooked up to a PC encoding the data no stability issues at all.

The client's project is running on a 72 MHz 32 bit ARM, so I think the 
bottleneck for higher resolution will primarily be how fast the serial 
link can be driven without too many errors.

It was about the simplest system for stable transmission of this amount 
of data over a serial link I could come up with without going the full 
monte and writing a "real" mpeg-ish image compression/decompression 
algorithm for each frame of data, with proper ECC to deal with the 
(almost guaranteed) errors like Huffman coding or something





[toc] | [prev] | [next] | [standalone]


#546808

FromWinfield Hill <winfieldhill@yahoo.com>
Date2019-06-11 10:28 -0700
Message-ID<qdoobu02mm7@drn.newsguy.com>
In reply to#546794
bitrex wrote...
>
> ... my test case was sending 256 pixels of 10 bit
> greyscale data over serial @ 57600 baud, ...

 The image is only 8x8, pretty small!


-- 
 Thanks,
    - Win

[toc] | [prev] | [next] | [standalone]


#546821

Frombitrex <user@example.net>
Date2019-06-11 14:31 -0400
Message-ID<psSLE.78563$BI2.54769@fx05.iad>
In reply to#546808
On 6/11/19 1:28 PM, Winfield Hill wrote:
> bitrex wrote...
>>
>> ... my test case was sending 256 pixels of 10 bit
>> greyscale data over serial @ 57600 baud, ...
> 
>   The image is only 8x8, pretty small!
> 
> 

16x16 but yeah, without some kind of true predictive coding compression 
and decompression scheme don't expect miracles over a 57600 or 115200 
serial link. Remember watching video clips using Realplayer over a 56k 
modem?

Fortunately the application doesn't require anything near even standard 
def. KISS

[toc] | [prev] | [next] | [standalone]


#546823

FromMartin Brown <'''newspam'''@nezumi.demon.co.uk>
Date2019-06-11 19:56 +0100
Message-ID<qdothk$kjm$1@gioia.aioe.org>
In reply to#546808
On 11/06/2019 18:28, Winfield Hill wrote:
> bitrex wrote...
>>
>> ... my test case was sending 256 pixels of 10 bit
>> greyscale data over serial @ 57600 baud, ...
> 
>   The image is only 8x8, pretty small!

I'm a bit puzzled by the very high error rate at 57k6 baud. I used to 
run at 230k4 back in the early 2000's without any significant errors.
I haven't used RS232 in ages preferring USB for fast serial today.

Is the environment electrically noisy with long cables or something?

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#546827

Frombitrex <user@example.net>
Date2019-06-11 15:32 -0400
Message-ID<9lTLE.23388$kt.5756@fx06.iad>
In reply to#546823
On 6/11/19 2:56 PM, Martin Brown wrote:
> On 11/06/2019 18:28, Winfield Hill wrote:
>> bitrex wrote...
>>>
>>> ... my test case was sending 256 pixels of 10 bit
>>> greyscale data over serial @ 57600 baud, ...
>>
>>   The image is only 8x8, pretty small!
> 
> I'm a bit puzzled by the very high error rate at 57k6 baud. I used to 
> run at 230k4 back in the early 2000's without any significant errors.
> I haven't used RS232 in ages preferring USB for fast serial today.
> 
> Is the environment electrically noisy with long cables or something?
> 

it's not "real" RS-232 serial it's serial over USB, using an FTDI 
interface chip.

also the serial port clock on the ATMega test receiver (just a 
mock-up/proof of concept, the actual client device is ARM based) is 
derived from the 16MHz master clock; I don't think 16MHz is a 
particularly amenable clock source for a 57600 baud rate:

<https://cache.amobbs.com/bbs_upload782111/files_22/ourdev_508497.html>

[toc] | [prev] | [next] | [standalone]


#546883

FromMartin Brown <'''newspam'''@nezumi.demon.co.uk>
Date2019-06-12 09:11 +0100
Message-ID<qdqc3j$teu$1@gioia.aioe.org>
In reply to#546827
On 11/06/2019 20:32, bitrex wrote:
> On 6/11/19 2:56 PM, Martin Brown wrote:
>> On 11/06/2019 18:28, Winfield Hill wrote:
>>> bitrex wrote...
>>>>
>>>> ... my test case was sending 256 pixels of 10 bit
>>>> greyscale data over serial @ 57600 baud, ...
>>>
>>>   The image is only 8x8, pretty small!
>>
>> I'm a bit puzzled by the very high error rate at 57k6 baud. I used to 
>> run at 230k4 back in the early 2000's without any significant errors.
>> I haven't used RS232 in ages preferring USB for fast serial today.
>>
>> Is the environment electrically noisy with long cables or something?
>>
> 
> it's not "real" RS-232 serial it's serial over USB, using an FTDI 
> interface chip.
> 
> also the serial port clock on the ATMega test receiver (just a 
> mock-up/proof of concept, the actual client device is ARM based) is 
> derived from the 16MHz master clock; I don't think 16MHz is a 
> particularly amenable clock source for a 57600 baud rate:
> 
> <https://cache.amobbs.com/bbs_upload782111/files_22/ourdev_508497.html>

I still find it odd that a FIFO on the USB serial receiver cannot cope 
at 57k6 baud. It isn't rocket science you divide 16MHz by 277.75 and 
suffer a tiny amount of jitter to get within 0.1% of the right rate. Or 
using the numbers in the table you have divide by 17+1/3 = 57692bd.

If it is physically connected over USB then why not implement the LCD 
display as removable storage medium and take advantage of the speed of 
USB. There are loads of industrial camera chips subverted for amateur 
astronomy that do this and get 250+ fps at lower resolutions. eg

https://astronomy-imaging-camera.com/product/asi120mm-s

320x240 @ 254fps on USB 3.0

I have its larger brother.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#546908

Frombitrex <user@example.net>
Date2019-06-12 11:33 -0400
Message-ID<OW8ME.27808$0i7.20910@fx25.iad>
In reply to#546883
On 6/12/19 4:11 AM, Martin Brown wrote:
> On 11/06/2019 20:32, bitrex wrote:
>> On 6/11/19 2:56 PM, Martin Brown wrote:
>>> On 11/06/2019 18:28, Winfield Hill wrote:
>>>> bitrex wrote...
>>>>>
>>>>> ... my test case was sending 256 pixels of 10 bit
>>>>> greyscale data over serial @ 57600 baud, ...
>>>>
>>>>   The image is only 8x8, pretty small!
>>>
>>> I'm a bit puzzled by the very high error rate at 57k6 baud. I used to 
>>> run at 230k4 back in the early 2000's without any significant errors.
>>> I haven't used RS232 in ages preferring USB for fast serial today.
>>>
>>> Is the environment electrically noisy with long cables or something?
>>>
>>
>> it's not "real" RS-232 serial it's serial over USB, using an FTDI 
>> interface chip.
>>
>> also the serial port clock on the ATMega test receiver (just a 
>> mock-up/proof of concept, the actual client device is ARM based) is 
>> derived from the 16MHz master clock; I don't think 16MHz is a 
>> particularly amenable clock source for a 57600 baud rate:
>>
>> <https://cache.amobbs.com/bbs_upload782111/files_22/ourdev_508497.html>
> 
> I still find it odd that a FIFO on the USB serial receiver cannot cope 
> at 57k6 baud. It isn't rocket science you divide 16MHz by 277.75 and 
> suffer a tiny amount of jitter to get within 0.1% of the right rate. Or 
> using the numbers in the table you have divide by 17+1/3 = 57692bd.
> 
> If it is physically connected over USB then why not implement the LCD 
> display as removable storage medium and take advantage of the speed of 
> USB. There are loads of industrial camera chips subverted for amateur 
> astronomy that do this and get 250+ fps at lower resolutions. eg
> 
> https://astronomy-imaging-camera.com/product/asi120mm-s
> 
> 320x240 @ 254fps on USB 3.0
> 
> I have its larger brother.
> 

Hi Martin, the LCD display output was only a proof-of-concept. The 
actual client-side item is a large array of LEDs controlled by TI LED 
driver chips. so I didn't have to have the big-ass thing sitting on my 
bench all the time!

It's physically large, but not high-resolution. The speed of serial 
connection seems to be perfectly adequate for it.

[toc] | [prev] | [next] | [standalone]


#546795

Frombitrex <user@example.net>
Date2019-06-11 11:42 -0400
Message-ID<IZPLE.29705$cZ6.22023@fx47.iad>
In reply to#546779
On 6/11/19 9:47 AM, Martin Brown wrote:
> On 10/06/2019 16:11, bitrex wrote:
>> On 6/10/19 4:10 AM, Martin Brown wrote:
>>> 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
>>
>> The encoding side is running on a desktop-class PC don't need any 
>> lookup table there.
> 
> If you have plenty of time on the encode side you might want to consider 
> another more costly form of data adaptive 12 bit to 8 bit encoding which 
> is based on greedy histogram equalisation. It requires an array to count 
> the frequency of every pixel value in the image and then multiple sweeps 
> of that to determine a histogram equalisation with ever increasing bin 
> widths to allocate the bins.
> 
> Initially you start with binsize=1 and Nbins= 256
> 
> target = Npixels/Nbins
> 
> It works very well on images with a lot of baseline values and a few 
> features. You have to transmit a lookup table with the byte values.
> 
> It is very good for looking for systematic errors on flat fields.
> 
> BTW You haven't said if the 8 bit comms was able to keep up.
> 

In summary, yeah works great man, got paid and client very happy :)

[toc] | [prev] | [next] | [standalone]


#546831

FromJohn Larkin <jjlarkin@highland_snip_technology.com>
Date2019-06-11 13:16 -0700
Message-ID<qo20gehdaj6cbkna74vsc3c9b3pvssbjdl@4ax.com>
In reply to#546779
On Tue, 11 Jun 2019 14:47:57 +0100, Martin Brown
<'''newspam'''@nezumi.demon.co.uk> wrote:

>On 10/06/2019 16:11, bitrex wrote:
>> On 6/10/19 4:10 AM, Martin Brown wrote:
>>> 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
>> 
>> The encoding side is running on a desktop-class PC don't need any lookup 
>> table there.
>
>If you have plenty of time on the encode side you might want to consider 
>another more costly form of data adaptive 12 bit to 8 bit encoding which 
>is based on greedy histogram equalisation. It requires an array to count 
>the frequency of every pixel value in the image and then multiple sweeps 
>of that to determine a histogram equalisation with ever increasing bin 
>widths to allocate the bins.
>
>Initially you start with binsize=1 and Nbins= 256
>
>target = Npixels/Nbins
>
>It works very well on images with a lot of baseline values and a few 
>features. You have to transmit a lookup table with the byte values.

FPGA bit streams tend to have long runs of 0s and 1s. Assuming that
anything else isn't worth compressing, one can write very simple
compression/decompression routines that cut the size of a binary
bitstream image by about 3:1. Serial bit-banging gets fast, too, when
you're blasting out long runs of 1 or 0.


-- 

John Larkin         Highland Technology, Inc
picosecond timing   precision measurement 

jlarkin att highlandtechnology dott com
http://www.highlandtechnology.com

[toc] | [prev] | [next] | [standalone]


#546840

Frombitrex <user@example.net>
Date2019-06-11 17:20 -0400
Message-ID<HWULE.78583$BI2.10804@fx05.iad>
In reply to#546831
On 6/11/19 4:16 PM, John Larkin wrote:
> On Tue, 11 Jun 2019 14:47:57 +0100, Martin Brown
> <'''newspam'''@nezumi.demon.co.uk> wrote:
> 
>> On 10/06/2019 16:11, bitrex wrote:
>>> On 6/10/19 4:10 AM, Martin Brown wrote:
>>>> 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
>>>
>>> The encoding side is running on a desktop-class PC don't need any lookup
>>> table there.
>>
>> If you have plenty of time on the encode side you might want to consider
>> another more costly form of data adaptive 12 bit to 8 bit encoding which
>> is based on greedy histogram equalisation. It requires an array to count
>> the frequency of every pixel value in the image and then multiple sweeps
>> of that to determine a histogram equalisation with ever increasing bin
>> widths to allocate the bins.
>>
>> Initially you start with binsize=1 and Nbins= 256
>>
>> target = Npixels/Nbins
>>
>> It works very well on images with a lot of baseline values and a few
>> features. You have to transmit a lookup table with the byte values.
> 
> FPGA bit streams tend to have long runs of 0s and 1s. Assuming that
> anything else isn't worth compressing, one can write very simple
> compression/decompression routines that cut the size of a binary
> bitstream image by about 3:1. Serial bit-banging gets fast, too, when
> you're blasting out long runs of 1 or 0.
> 
> 

run-length encoding doesn't work well at all for raw bitmap/pix-map 
image data there aren't enough runs of identical binary digits in most 
video frames to make it worth the overhead by itself. JPG uses it after 
the image has been quantized to something more resembling palette-based.

[toc] | [prev] | [next] | [standalone]


#546841

Frombitrex <user@example.net>
Date2019-06-11 17:30 -0400
Message-ID<z3VLE.10869$t_3.2468@fx18.iad>
In reply to#546831
On 6/11/19 4:16 PM, John Larkin wrote:
> On Tue, 11 Jun 2019 14:47:57 +0100, Martin Brown
> <'''newspam'''@nezumi.demon.co.uk> wrote:
> 
>> On 10/06/2019 16:11, bitrex wrote:
>>> On 6/10/19 4:10 AM, Martin Brown wrote:
>>>> 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
>>>
>>> The encoding side is running on a desktop-class PC don't need any lookup
>>> table there.
>>
>> If you have plenty of time on the encode side you might want to consider
>> another more costly form of data adaptive 12 bit to 8 bit encoding which
>> is based on greedy histogram equalisation. It requires an array to count
>> the frequency of every pixel value in the image and then multiple sweeps
>> of that to determine a histogram equalisation with ever increasing bin
>> widths to allocate the bins.
>>
>> Initially you start with binsize=1 and Nbins= 256
>>
>> target = Npixels/Nbins
>>
>> It works very well on images with a lot of baseline values and a few
>> features. You have to transmit a lookup table with the byte values.
> 
> FPGA bit streams tend to have long runs of 0s and 1s. Assuming that
> anything else isn't worth compressing, one can write very simple
> compression/decompression routines that cut the size of a binary
> bitstream image by about 3:1. Serial bit-banging gets fast, too, when
> you're blasting out long runs of 1 or 0.
> 
> 

Transmitting moving pictures over meh-bandwith digital links "properly" 
is mostly a solved engineering problem; you use some kind of FFT-based 
lossy compression algorithm like mp2 and error correcting codes over the 
link.

It would take a while to create a custom implementation from scratch. 
buuut this client wasn't paying nearly enough to implement all that 
jazz, and not convinced the desired receive hardware could pull it off. 
It's an engineering rat hole. Maybe someday for fun I try it.

[toc] | [prev] | [next] | [standalone]


#546860

Fromdavid eather <eatDELETEher@tpg.com.au>
Date2019-06-12 11:05 +1000
Message-ID<CdYLE.618$ql7.77@fx35.am4>
In reply to#546566

On 10/06/2019 5:03 am, 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);
>> }
>>
>> 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.
> 
> We do FPGA and uP based functions with lookups, and sometimes a bit of
> interpolation. Like for DDS sine waves.
> 
A look-up table has my vote

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | sci.electronics.design


csiph-web