Page 1 of 1

All kind of lossless image compression

Posted: 2016-07-03T11:52:43-07:00
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).

Re: All kind of lossless image compression

Posted: 2016-07-03T12:00:24-07:00
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

Re: All kind of lossless image compression

Posted: 2016-07-03T12:03:18-07:00
by useratimgmgck
I saw that text, but can't reproduce compression.

Re: All kind of lossless image compression

Posted: 2016-07-03T12:31:35-07:00
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.

Re: All kind of lossless image compression

Posted: 2016-07-03T12:52:37-07:00
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?

Re: All kind of lossless image compression

Posted: 2016-07-03T14:02:47-07:00
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.

Re: All kind of lossless image compression

Posted: 2016-07-03T14:04:06-07:00
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.)

Re: All kind of lossless image compression

Posted: 2016-07-03T14:07:27-07:00
by fmw42
See -quality at http://www.imagemagick.org/script/comma ... hp#quality for control of PNG compression

Re: All kind of lossless image compression

Posted: 2016-07-06T10:05:23-07:00
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...

Re: All kind of lossless image compression

Posted: 2016-07-06T11:45:00-07:00
by fmw42
I do not know where you can get the patched libjpeg as mentioned earlier

Re: All kind of lossless image compression

Posted: 2016-07-20T18:35:00-07:00
by 246246
I have not tried yet, but did you try it?
https://github.com/thorfdbg/libjpeg
See Readme that mentioned about lossless.

Re: All kind of lossless image compression

Posted: 2016-07-21T21:29:17-07:00
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.

Re: All kind of lossless image compression

Posted: 2016-07-22T06:35:24-07:00
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.

Re: All kind of lossless image compression

Posted: 2016-07-22T17:46:37-07:00
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.