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.