Results 1 to 7 of 7

Thread: Image compression for microcontroller

  1. #1
    Member
    Join Date
    Nov 2015
    Location
    Toronto, Canada
    Posts
    2
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Image compression for microcontroller

    I would like to get suggestion on what algorithm would be the best to use to compress images with microcontroller with limited RAM and program memory size.

    In my project I'm trying to send images from VGA camera connected to microcontroller over a slow communication line. Images need to be compressed otherwise the comm. line speed will not allow to send desired number of frames per second.
    My goal is to send 12 frames per second of 640x480 pixel frames. I will read 3 bytes per pixel (RGB) from camera. So on input I will have 640 x 480 x 3 x 12fps -> around 11 MB/s. My communication line is capable of 3 MB/s so I'm looking for algorithm that could give me around 1:4 compression ratio on average for generic images of people. Quality of image is not critical so I think 5 bits per color would be enough if this would make things easier (ratio 1:3).

    My initial thinking was to use some standard or modified jpg encoder algorithm but my concern is that the processing power of my micro controller might not allow to compress enough frames per second.

    Constraints:
    - main criteria is compression speed
    - lossy compression is OK
    - decompressed quality not critical
    - goal is to get 1:3 or 1:4 compression ratio
    - compressed format does not need to be standard as I will be writing code for receiving device
    - compression will be done by 200MHz 32-bit ARM Cortex-M4 micro (think early Pentium-3 in terms of computing power) with no more then 4MB RAM for frame buffer and compression.
    - compression code with all required libraries must fit to 512 KB.
    - I will use recent gcc compiler for ARM and C/C++

    Are there open-source algorithms available with faster compression of images then jpg that would fit these constraints? I would appreciate any suggestions and advice.
    Branislav

  2. #2
    Member
    Join Date
    Jun 2015
    Location
    Switzerland
    Posts
    667
    Thanks
    204
    Thanked 241 Times in 146 Posts
    Quote Originally Posted by branislav View Post
    I would like to get suggestion on what algorithm would be the best to use to compress images with microcontroller with limited RAM and program memory size.
    Spatial prediction error vector quantization to a static table complemented with a simple entropy code seems like an option. This kind of an encoder was recently added to libwebp -- it is slightly lossy, but it is using the lossless decoder to decode the image. See https://groups.google.com/a/webmproj...ss/W-iFWM1jGh8

    Experiment with the experimental cwebp/dwebp pair and try out the delta-palettization option there to understand what kind of quality you would get.

    Most likely you would need something simpler/faster/lesser compression for your requirements, but there is also a chance that libwebp would fit your need out of the box. When measuring compression speed use, -z 0 (or both -q 0 and -m 0).

  3. The Following User Says Thank You to Jyrki Alakuijala For This Useful Post:

    branislav (15th November 2015)

  4. #3
    Member
    Join Date
    Aug 2010
    Location
    Seattle, WA
    Posts
    79
    Thanks
    6
    Thanked 67 Times in 27 Posts
    I've implemented JPEG decompression on an 8-bit microcontroller (PIC18F):
    https://code.google.com/p/picojpeg/

    JPEG compression is less computationally expensive from what I remember (no Huffman decoding overhead). The main bottlenecks will be things like chroma downsampling and the 8x8 DCT.

    At 200 MHz at 12fps you have approx. 16 megacycles of computation available per frame, or around 54 cycles available per pixel at 640x480. This doesn't seem *too* out of the question if the code is well optimized.

  5. The Following User Says Thank You to rgeldreich For This Useful Post:

    branislav (16th November 2015)

  6. #4
    Member
    Join Date
    May 2006
    Location
    Uruguay
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post
    There is also JPEG-LS / LOCO-I, there are multiple implementations listed at http://www.stat.columbia.edu/~jakulin/jpeg-ls/
    However, while fast, I'm not sure it's suitable for your purposes as the lossy mode targets a maximum loss rather than a fixed bpp and I didn't find a implementation tested on ARM (but I didn't search much).

  7. The Following User Says Thank You to ggf31416 For This Useful Post:

    branislav (16th November 2015)

  8. #5
    Member
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    Why not use a raspberry pi 2b. it has 4 cores and runs @900 mhz. You can run a standard distro on it and this includes libjpeg etc.

    E

  9. #6
    Member
    Join Date
    Nov 2015
    Location
    Toronto, Canada
    Posts
    2
    Thanks
    4
    Thanked 0 Times in 0 Posts
    @edcassa - for this project I really need microcontoller - there are other functions that it needs to do.

    Yesterday I have ported "Blackfin Fast JPEG Encoding" code to my micro from forum: http://blog.frankvh.com/2009/06/09/b...jpeg-encoding/
    Code works great but it takes around 160 ms to encode 320x240 YUV422 frame (around 6fps) on my micro.
    Aprox. time to encode one frame: total 160ms, reading data: 22ms, DCT:45ms, quantization: 25ms, huffman: 60ms

    As far as I can tell the DCT code used is one of the fast algorithms. I looked at generated assembly and it is amazing what the compiler can do these days. I don't think I would get much improvement by converting to asm, at least of the DCT code.
    Assuming I will be able to improve reading data, quantization and huffman somewhat I might be able to get to 8-10fps for 320x240 as an optimistic guess.

    I think I will try JPEG-LS now. Anyone has other suggestions please let me know.

    Thanks
    Branislav

  10. #7
    Member
    Join Date
    Apr 2012
    Location
    Stuttgart
    Posts
    437
    Thanks
    1
    Thanked 96 Times in 57 Posts
    Quote Originally Posted by branislav View Post
    I think I will try JPEG-LS now. Anyone has other suggestions please let me know.
    1:4 is possible with JPEG LS, though may already create some visible distortions in some places because it cannot confine coding errors spatially - they tend to create long horizontal stripes that may become visible on flat backgrounds.

    *If* you try JPEG LS, may I suggest to also use the lossless color transformation from part-2 of JPEG LS? You find a JPEG implementation capable of (some parts of) JPEG LS part 2 on www.jpeg.org, namely at
    http://www.jpeg.org/downloads/jpegxt...12_gpl_src.zip

    This is the JPEG XT reference software (yes, really). For JPEG LS support, get the GPL version (not the ISO version, which does not include JPEG LS support). To run it, use the following command line for compression:

    jpeg -cls -ls 1 -m 3 <input> <output>

    where <input> is the input file in ppm format and <output> is the output file. "-m 3" limits the maximum pixel error to 3, and in my case, a compression ratio of approximately 1:4.

    Note, however, that JPEG LS is no constant bitrate codec, i.e. it cannot *enforce* a 1:4 compression all the time. It can enforce a maximum l^infinity error.

    If you are looking at a lightweight constant-bitrate codec, you may need to wait for JPEG XS (yes, really, no kidding!), our next standard. (-:

  11. The Following User Says Thank You to thorfdbg For This Useful Post:

    branislav (17th November 2015)

Similar Threads

  1. WebP (lossy image compression)
    By Arkanosis in forum Data Compression
    Replies: 62
    Last Post: 12th April 2019, 18:45
  2. UCI Image Compression
    By maadjordan in forum Data Compression
    Replies: 5
    Last Post: 19th August 2017, 23:15
  3. Image Compression Challenge at PCS 2015
    By thorfdbg in forum Data Compression
    Replies: 0
    Last Post: 8th February 2015, 15:20
  4. BCIF image compression program
    By m^2 in forum Data Compression
    Replies: 35
    Last Post: 26th April 2013, 16:02
  5. 3d image compression
    By m^2 in forum Data Compression
    Replies: 5
    Last Post: 9th July 2012, 08:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •