All kind of lossless image compression

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

All kind of lossless image compression

Post by useratimgmgck »

Hello, I have read documentation, but I didn't understand how to LOSSLESSLY compress image.

So, input data are:
1. I have image in BMP file format, let's it be "testimage.bmp" (8bpp or 24bpp).
2. My operation system is Windows and I need all actions be executed from the command line.
3. I have downloaded (ImageMagick-7.0.2-2-Q16-x64-dll.exe) from http://www.imagemagick.org/script/binary-releases.php
4. I run "cmd.exe", do "cd C:\imagemagick".

I need to perform all possible types of LOSSLESS image compression, that ImageMagick do provide. At least I need:
- JPEG-LS,
- JPEG2000,
- PNG.

Questions
1. Please, specify command lines "how to achieve my goal" (and C++ functions if possible).
2. Do you know another FREEWARE image compressors, which works on WINDOWS and provides command line interface for LOSSLESS image compression? I know only "OptiPNG", "nconvert" (doesn't support JPEG-LS, JPEG2000 as I know).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: All kind of lossless image compression

Post by fmw42 »

IM supports JPEG2000 and PNG and TIFF LZW, ZIP compressions and supposedly Lossless JPEG. See http://www.imagemagick.org/script/comma ... p#compress
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by useratimgmgck »

I saw that text, but can't reproduce compression.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: All kind of lossless image compression

Post by snibgo »

Lossless JPEG2000: no problem, just write to a .jp2 file.

Lossless PNG: no problem, just write to a .png file.

Lossless TIFF: no problem, just write to a .tif or .tiff file, with "-compress XX" where XX is anything except JPEG.

Lossless JPG: The pre-built Windows binaries can't do this. JPG is always lossy.
snibgo's IM pages: im.snibgo.com
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by useratimgmgck »

Thank you, I have tried as you wrote
1. Conversion "magick testimage.bmp testimage.jp2" works lossless. OK.
2. Conversion "magick testimage.bmp testimage.png" works lossless. It works a little bit worse (compression ratio) than OptiPNG (less than 1% at test image). OK

So, I have found JPEG2000 and PNG "Free Windows Command-line" lossless compressors now. Does anyone know JPEG-LS "Free Windows Command-line" lossless compressor?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: All kind of lossless image compression

Post by fmw42 »

The link above that I mentioned says

"Lossless refers to lossless JPEG, which is only available if the JPEG library has been patched to support it. Use of lossless JPEG is generally not recommended."

So you need some patched libjpeg for that to work. I do not know where to get such. It also says this is not recommended.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: All kind of lossless image compression

Post by snibgo »

For PNG, IM has many options to influence the degree of compression, which is always lossless. Or just use the program pngcrush. (Which was written by the same chap who wrote the IM PNG code.)
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: All kind of lossless image compression

Post by fmw42 »

See -quality at http://www.imagemagick.org/script/comma ... hp#quality for control of PNG compression
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by useratimgmgck »

JPEG-LS compression is still actual problem for me (I didn't find JPEG-LS support in libjpeg). No problem if it is not recommended. Would like it to be possible at least...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: All kind of lossless image compression

Post by fmw42 »

I do not know where you can get the patched libjpeg as mentioned earlier
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by 246246 »

I have not tried yet, but did you try it?
https://github.com/thorfdbg/libjpeg
See Readme that mentioned about lossless.
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by useratimgmgck »

Good news, thank you!
I never used github projects before. I have Visual Studio 2012 Professional.
Couldn't you advise, what I have to do?
I did
1. download (pushed the button "Clone or download")
2. open the folder "vs10.0"
I would like to have executable with short instructions "how to compress input image".
I did read "README", and when it's talking about lossless compression, it mentions DCT. As I know, JPEG-LS doesn't use DCT.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by 246246 »

As I looked the README, I think what you need is -ls option. Check line 138.
I'm not familiar with Visual Studio. In my Mac, I can build jpeg executable, however failed to build library, but I could do a simple check with the generated jpeg command.

Example in README is slightly wrong. -ls option requires mode.

Code: Select all

-ls mode   : encode in JPEG LS (NOT 10918) mode, where 0 is scan-interleaved,
             1 is line interleaved and 2 is sample interleaved.
             NOTE THAT THIS IS NOT 10918 (JPEG) COMPLIANT, BUT COMPLIANT TO
             14495-1 (JPEG-LS) WHICH IS A DIFFERENT STANDARD.
             Use -c to bypass the YCbCr color transformation for true lossless,
             also use -c for decoding images encoded by the UBC reference software
             as it does not write an indicator marker to disable the
             transformation itself.
             Note that the UBC software will not able to decode streams created by
             this software due to a limitation of the UBC code - the streams are
             nevertheless fully conforming.
Also this command accept only pnm format as a input. So you need to convert your bmp to ppm first. Then

$ ./jpeg -ls 0 -c input.ppm output.jpg

would convert it to jpeg. I suggest further questions should be posted to the author in that forum or directly.
useratimgmgck
Posts: 6
Joined: 2016-07-03T11:34:06-07:00
Authentication code: 1151

Re: All kind of lossless image compression

Post by useratimgmgck »

Yes, it works. There are some observations.
1. XnView doesn't read JPEG-LS file made by this library (but files made by another JPEG-LS codec reads successfully).
2. This library compresses little bit worse (0.1%) than some other JPEG-LS codecs.
Post Reply