Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an image loses quality when it is converted from jpg to png?

Tags:

png

jpeg

We all know that converting from jpg to jpg makes an image lose quality, and that the same doesn't happen when it's png to png, but what about jpg to png ?

In my mind it makes sense that it doesn't, but still I'm not sure.

I think that good answer to this question probably would be an article in which there would be a good explanation of why it happens or not. Do you now of any ? I couldn't find such article.

like image 775
Fábio Linhares Avatar asked Jul 24 '16 16:07

Fábio Linhares


People also ask

Does converting JPG to PNG improve quality?

In seconds, you can convert your JPG images to PNG format. PNG files offer capabilities such as transparency, faded edges, and higher quality compression.

What happens if I convert JPG to PNG?

A JPG image's quality will degrade slightly each time it is saved, while a PNG file is a "lossless" format, meaning that its quality will not change over time. You can use an online conversion service to turn your JPG files into PNG files, or you can use your Windows or Mac computer's built-in options.

How do I convert a JPEG to a PNG without losing quality?

Paint is a built-in Windows tool that you can use it to convert a PNG image to JPEG without losing quality. , open the PNG image with Paint. Open the PNG image with Paint and navigate to File > Save as > JPEG picture. Then, choose a location, add a name, and make sure the file format is set to JPEG.

Does PNG decrease quality?

In contrast, PNG files benefit from lossless compression. This means no data is lost when the image is compressed — the quality stays the same no matter how many times you edit and save the file. The image won't become blurry or distorted, making PNGs ideal for sharp logos and graphs containing lots of figures.


2 Answers

It doesn't, but it's complicated.

Reading of JPEG is not a precisely defined process. Different JPEG decoders are allowed to produce slightly different results from the same file.

Converting JPEG to PNG makes pixels forever represent the particular method that was used to decode the JPEG, even if it wasn't the best one. If you use a "bad" JPEG decoder for the conversion you lose ability to use a "better" JPEG decoder later.

The differences are:

  • Chroma upsampling. JPEG may store chroma (~color) at lower resolution than luma (~brightness) of the image. The spec doesn't say how the chroma channel should be resized, so some decoders use blocky nearest-neighbor scaling, some use bilinear scaling, some do even weirder things.

  • Numeric precision. JPEG requires calculations to be done to convert image from DCT and YCbCr representation to RGB. This can be done quickly and cheaply using integer math and 8-bit color, or a tiny bit better using floating-point math and higher-depth color.

  • Color profiles and CMYK. Conversion may change color space (in case of CMYK it has to convert to RGB), which is easy to get wrong.

There are other reasons to avoid the conversion:

  • The file will almost certainly become much larger. JPEG compression artifacts are the worst case for PNG.
  • The file will lose metadata (like camera info, GPS). While in theory PNG could carry the same metadata, in practice converters rarely preserve it.

And a case for conversion: jpeg2png project, which doesn't merely convert the file, but also uses quite advanced post-processing to smooth out JPEG compression distortions. In that case you might salvage a low-quality blocky JPEG and get a smoother image instead.

like image 90
Kornel Avatar answered Oct 22 '22 11:10

Kornel


The process you describe is:

  1. JPEG Stream => JPEG DECODER => BITMAP
  2. => PNG ENCODER => PNG Stream

There is no change in step #2. Step #1 might have rounding errors inherent in JPEG.

like image 32
user3344003 Avatar answered Oct 22 '22 11:10

user3344003