OpenCV PNG compression gets much worse results than gimp at max compression (Bug #1452)


Added by Kevin Watts over 13 years ago. Updated almost 13 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:highgui-images
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I tried to compress the attached image with OpenCV's PNG compression "imencode". I started with a PNG image from GIMP, at 136KB. I set the PNG compression to "9" for maximum compression. OpenCV compressed the image to 700KB.

This users thread seems to point at the PNG compression strategy.
http://tech.groups.yahoo.com/group/OpenCV/message/81110

Is there any other option that we should enable to get better PNG compression? Thanks.


willow_test.png (135.8 kB) Kevin Watts, 2011-10-28 01:38 am


Associated revisions

Revision 17c31027
Added by Vadim Pisarevsky over 13 years ago

improved png compression ratio (ticket #1452)

Revision 448a2527
Added by Vadim Pisarevsky over 13 years ago

added compression strategy as a parameter (another request from ticket #1452)

Revision 8853d19e
Added by Alexander Smorkalov over 11 years ago

Merge pull request #1452 from alalek:fix_cv_export_templates

History

Updated by Vadim Pisarevsky over 13 years ago

thanks for the link! Indeed, by changing compression strategy to Z_FILTERED in grfmt_png.cpp we can compress the attached file downto 151Kb instead of 700Kb. It's not quite GIMP level yet, but is much better than before. Surprisingly, the speed was increased too, probably because >4.5x less data needs to be stored to disk. The fix is in SVN trunk, r6921

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Updated by Kevin Watts over 13 years ago

Thanks for the quick fix. I don't want to get greedy here, but can we make this parameterizable? I'm not sure why Z_HUFFMAN_ONLY works so well in this case, but it looks like Z_FILTERED is designed for PNG's. Maybe we can make Z_HUFFMAN_ONLY the default, but Z_FILTERED an option.

http://www.libpng.org/pub/png/book/LCH-png-chapter.pdf (page 7)

  • Status changed from Done to Cancelled
  • (deleted custom field) deleted (fixed)

Updated by Vadim Pisarevsky over 13 years ago

makes sense. In trunk, r6922, I added IMWRITE_PNG_STRATEGY parameter with different IMWRITE_PNG_STRATEGY_... possible values. Also, I found that the Z_RLE (aka IMWRITE_PNG_STRATEGY_RLE) seems to be the best option on most images - it's nearly as fast as HUFFMAN_ONLY, and yet it compresses many images very well. E.g. it compressed willow_test.png down to 137kb, the same result as GIMP. So I made RLE strategy the default one.

  • Status changed from Cancelled to Done
  • (deleted custom field) set to fixed

Updated by Andrey Kamaev almost 13 years ago

  • Target version set to 2.4.0

Also available in: Atom PDF