简体   繁体   中英

Lossless JPEG file writing

I have a question with regard to JPEG file writing. Suppose I have a PNG file example.png, and I want to change the file format to JPEG without any information loss. For the now being, I have two solutions:

  • Solution 1: perform the file formatting transformation with MATLAB

    I = imread('example.png');

    imwrite(I,'example.jpg','Mode','lossless');

    II = imread('example.jpg');

    differ = I-II;

    max(differ(:))

    This solution can produce lossless JPEG files. However, the problem with this solution is that some information in the original image such as the DPI resolution may be lost. Moreover, the produced output image cannot be viewed by popular image viewers such as IrfanView and Windows Paint.

  • Solution 2: use IrfanView software. Use the "Save as" function of IrfanView program, we can change the file format very easily. However, although I have set 'best quality 100' option when saving the JPEG file, the output image also show some information loss. The difference between these two images are not zero for all the pixels.

I am therefore wondering what I should do in order to solve the problem. Any ideas will be appreciated.

This problem has no solution (yet, as of 2018).

You can't avoid use of lossy compression if you want the JPEG file to be usable in majority of image viewers.

The commonly supported version of JPEG is based on DCT compression, which - by definition - performs transformation and rounding that causes some precision loss.

The alternative, lossless JPEG compression method, JPEG-LS, is rarely supported.

There's also JPEG-XT extension that's a combination of lossy image + layer for reconstruction of the lossless original. It fails gracefully in JPEG image viewers, but it's even newer, and I don't know if it's implemented anywhere yet.

If you really need lossless, use PNG. With JPEG the best you can get is minimally lossy JPEG in RGB colorspace at quality=100 (which isn't literally 100%).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM